When I change ddl.Visible=true(it gets changed on partial postback/updatepanel from another form element event)the RequiredFieldValidator will not fire?
NOTE: This is not a question on how to use the RequiredFieldValidator in a normal circumstance. My form has cascading dropdowns that are all dynamically built with their visibility toggled on and off.
<asp:DropDownList ID="ddl" Visible="false" AutoPostBack="True" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="ddl"
ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Required"></asp:RequiredFieldValidator>
You need to set the
InitialValueproperty on yourRequiredFieldValidatorso that it knows when the value of theDropDownListhas changed. For example, on a dropdown with these values:You would add this attribute
to your
RequiredFieldValidator.Without knowing if the value has changed it is impossible for the validator to know whether or not the user has satisfied its requirement.