I have a textbox and dropdown inside a <td>
based on certain condition I'll have to hide the text box and show the dropdown. If dropdown is visible is it possible to use the same requiredfield Validator. Is this possible?
<td>
<asp:TextBox ID="txtLimit" runat="server" />
<asp:DropDownList ID="ddlCurLiabiltyLimits" runat="server" CssClass="TextNormal" OnSelectedIndexChanged="ddlCurLiabiltyLimits_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtLimit" ErrorMessage="Answer is required." ClientIDMode="Static" />
</td>
In my code behind :
RequiredFieldValidator1.ControlToValidate = ddlCurLiabiltyLimits.ID ;
but this doesn't seem to be working.
One thing that might be causing you problems is when using RequiredFieldValidator on a DropDownList, you will want to specify the RequiredFieldValidator.InitialValue property to indicate the Value of the "first" item in the DropDownList. Maybe that is where your problem is?