?
Solved

Asp:RequiredFieldValidator cause validation on Server even if validator is disabled

Posted on 2011-03-25
3
Medium Priority
?
504 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:MickyMc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
nbove earned 2000 total points
ID: 35218862
This seems like a ViewState issue.  Do you have viewstate disabled for the page?  What it sounds like is that the dynamic user controls are not preserving their "Required" state between postbacks.  Typically this would be handled by viewstate, but in the case of dynamic controls, things can get tricky.

The following article has a pretty good explanation about viewstate:
http://msdn.microsoft.com/en-us/library/ms972976.aspx
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35877221
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question