MickyMc
asked on
Asp:RequiredFieldValidator cause validation on Server even if validator is disabled
Hi there, I will keep this as short as possble but its wrecking my head. I have a user control with a label and a field. I add this dynamically to a page at run time. There could be many. The user control has a RequiredFieldValidator and looks all like this. The validator is enabled by default.
When I dynamically load the control I check a parameter to tell me if the field is required or not. The paramater is from the database for this control that I am about to draw. If the Field NOT a required field I disable the validation in the page_preRender.. also tried it in load.
So far so good. This all works on the client side validation for only the user controls with the Display Required set to true, leaving the Validator enabled.
however on post page from a submit button which I have wired to the same validation group as the user controls, I check the IsValid on the submit and if its false I dont save anything. But when the page re-renders on the client.. I have error messages on all the user controls, even though I disabled them.
Any idea.. thanks
<div class="controlCell">
<asp:TextBox ID="dfControl" runat="server" Text="" ToolTip="ucsAlphanumericEntryDC" Width="95%" CausesValidation="true"/>
<asp:RequiredFieldValidator ID="rfvContol" runat="server" ErrorMessage="Value is required" EnableClientScript="true"
ValidationGroup="ValidateContols" ControlToValidate="dfControl" Display="Dynamic" Enabled="true"></asp:RequiredFieldValidator>
</div>
When I dynamically load the control I check a parameter to tell me if the field is required or not. The paramater is from the database for this control that I am about to draw. If the Field NOT a required field I disable the validation in the page_preRender.. also tried it in load.
if (!DisplayRequired)
{
rfvContol.EnableClientScript = false;
rfvContol.Enabled = false;
dfControl.CausesValidation = false;
}
So far so good. This all works on the client side validation for only the user controls with the Display Required set to true, leaving the Validator enabled.
however on post page from a submit button which I have wired to the same validation group as the user controls, I check the IsValid on the submit and if its false I dont save anything. But when the page re-renders on the client.. I have error messages on all the user controls, even though I disabled them.
Any idea.. thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.