Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. required field validator is not working properly for dropdownlist

required field validator is not working properly for dropdownlist

Scheduled Pinned Locked Moved ASP.NET
helpsharepointwpfwcfsysadmin
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chakran
    wrote on last edited by
    #1

    Hi, I am facing a problem with the validator. Required field validator is not displaying error message for the control dropdown. am binding dropdown with the datatable. and set the initial value property as "select product" in the required field validatior.If i didnot select any thing from ddl and click button its not showing any error message...below is my code. // Binding the dropdonwn with the data table DataTable datatable = GetDataFromDB("SP_GetProducts", "All"); DropDownList2.DataSource = datatable; DropDownList2.DataTextField = "Product Name"; DropDownList2.DataValueField = "Product ID"; DropDownList2.DataBind(); DropDownList2.Items.Insert(0, "Select Product"); <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" Height="22px" Width="234px"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DropDownList2" Display="None" ErrorMessage="Please select the product" InitialValue="Select Product" ValidationGroup="Calculation" >*</asp:RequiredFieldValidator> <asp:Button ID="Button1" runat="server" Text="Calculate" Height="22px" onclick="Button1_Click" ValidationGroup="Calculation" /> can any one tell me where I was wrong...

    D 1 Reply Last reply
    0
    • C chakran

      Hi, I am facing a problem with the validator. Required field validator is not displaying error message for the control dropdown. am binding dropdown with the datatable. and set the initial value property as "select product" in the required field validatior.If i didnot select any thing from ddl and click button its not showing any error message...below is my code. // Binding the dropdonwn with the data table DataTable datatable = GetDataFromDB("SP_GetProducts", "All"); DropDownList2.DataSource = datatable; DropDownList2.DataTextField = "Product Name"; DropDownList2.DataValueField = "Product ID"; DropDownList2.DataBind(); DropDownList2.Items.Insert(0, "Select Product"); <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" Height="22px" Width="234px"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DropDownList2" Display="None" ErrorMessage="Please select the product" InitialValue="Select Product" ValidationGroup="Calculation" >*</asp:RequiredFieldValidator> <asp:Button ID="Button1" runat="server" Text="Calculate" Height="22px" onclick="Button1_Click" ValidationGroup="Calculation" /> can any one tell me where I was wrong...

      D Offline
      D Offline
      Dinesh Mani
      wrote on last edited by
      #2

      Validator controls are case sensitive! So, select product and Select Product are different! HTH!!

      C 1 Reply Last reply
      0
      • D Dinesh Mani

        Validator controls are case sensitive! So, select product and Select Product are different! HTH!!

        C Offline
        C Offline
        chakran
        wrote on last edited by
        #3

        yes I gave the same... pls check in the code once again.... but button_click event is not firing if we don't select anything from ddl... only the issue is its not displaying error message....

        D 1 Reply Last reply
        0
        • C chakran

          yes I gave the same... pls check in the code once again.... but button_click event is not firing if we don't select anything from ddl... only the issue is its not displaying error message....

          D Offline
          D Offline
          Dinesh Mani
          wrote on last edited by
          #4

          I'm sorry, I just checked the text and the DDL definition! My bad!! I think you should change the Display property on the validation control from Display="None" to Display="Dynamic".

          C 1 Reply Last reply
          0
          • D Dinesh Mani

            I'm sorry, I just checked the text and the DDL definition! My bad!! I think you should change the Display property on the validation control from Display="None" to Display="Dynamic".

            C Offline
            C Offline
            chakran
            wrote on last edited by
            #5

            thanks. working fine..

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups