Link to home
Start Free TrialLog in
Avatar of MickyMc
MickyMcFlag for Ireland

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.

    <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>

Open in new window


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;
                }

Open in new window


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
Avatar of Nathan Bove
Nathan Bove
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.