required field validator is not working properly for dropdownlist
-
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...
-
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...
Validator controls are case sensitive! So, select product and Select Product are different! HTH!!
-
Validator controls are case sensitive! So, select product and Select Product are different! HTH!!
-
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....
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".
-
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".