BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

Last post 04-27-2007 11:08 PM by chetan.sarode. 11 replies.

Sort Posts:

  • BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    09-27-2006, 9:21 PM
    • Loading...
    • haller
    • Joined on 09-28-2006, 12:54 AM
    • Posts 1

    Note: this post is about regular ASP.NET Validators, not Atlas Validators. 

    I am using the July CTP of Atlas.  I have a Web form with some fields and validators inside an UpdatePanel and some fields and validators outside.  In this setup, any asynchronous postback breaks subsequent client-side validation.  After an AJAX call, any button click outside the UpdatePanel causes the page to post back to the server, despite the fact that some client-side validators (outside the UpdatePanel) are invalid.

    This seems to happen because as soon as the async. postback happens, JavaScript code is being sent back to the client that declares a Page_Validators array containing only the validators inside the UpdatePanel.  When the client-side validation is fired next time, only the validators in the new Page_Validators array are validated, the ones in the original one (which contained all validators on the page) are ignored.

    This behavior appears to be caused by the fact that the Render() method on BaseValidator calls a method called RegisterValidatorDeclaration(), which in turns calls Page.ClientScript.RegisterArrayDeclaration() on the Page_Validators JavaScript array.  When an async. postback happens, Render() is called only on the validators in the UpdatePanel, and thus the resulting array contains only those validators.  The expected behavior, IMHO, is that the Page_Validators array is not regenerated at all.

    This is just my theory from reading System.Web code via Reflector, I cannot verify it.

    The test page below can be used to easily reproduce the problem.

    Any fix, workaround or suggestion would be greatly appreciated!  Atlas would be a great improvement to our application's UX, but if it breaks (existing) validation, we will not be able to use it Sad

    <%@ Page Language="VB" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    Protected Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    lblResult.Text = "Button 1 Clicked!"
    End Sub

    Protected Sub btn2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    lblResult.Text = "Button 2 Clicked!"
    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Atlas / Validator Bug Test</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <atlas:ScriptManager runat="server" ID="ScriptMgr" EnablePartialRendering="true" EnableScriptGlobalization="false" />
    <h3>
    Atlas / Validator Bug Test</h3>
    Instructions: click Button 1, then erase text from the Text 2 textbox and click
    Button 2. Postback occurs where it shouldn't!
    <asp:ValidationSummary runat="server" ID="vs1" />
    <atlas:UpdatePanel runat="server" ID="upValidation">
    <ContentTemplate>
    <asp:Label ID="lblResult" runat="server" ForeColor="blue" />
    <br />
    <br />
    <asp:RequiredFieldValidator ID="rqfv1" runat="server" ControlToValidate="txt1" ErrorMessage="Enter Text 1" Text="*" />
    Text 1:
    <asp:TextBox ID="txt1" runat="server" Text="foo" />
    <asp:Button ID="btn1" runat="server" Text="Button 1" CausesValidation="true" OnClick="btn1_Click" />
    </ContentTemplate>
    </atlas:UpdatePanel>
    <asp:RequiredFieldValidator ID="rqfv2" runat="server" ControlToValidate="txt2" ErrorMessage="Enter Text 2" Text="*" />
    Text 2:
    <asp:TextBox ID="txt2" runat="server" Text="bar" />
    <asp:Button ID="btn2" runat="server" Text="Button 2" CausesValidation="true" OnClick="btn2_Click" />
    </form>
    </body>
    </html>
     
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-03-2006, 2:59 PM
    I have run into the same problem and using reflector, come to the same conclusion. Is there a work-around out there?
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-03-2006, 5:48 PM
    Answer
    • Loading...
    • Eilon
    • Joined on 06-26-2002, 6:14 PM
    • Redmond, WA
    • Posts 716
    • AspNetTeam

    I'm afraid that in the current CTPs there are a number of known issues with the ASP.NET Validators when used with UpdatePanels.

    The good news is that when we release Atlas 1.0 we'll have updated versions of the validators that are compatible with the UpdatePanel. You'll be able to have them inside, outside, and wherever along with UpdatePanels and they'll work.

    Thanks,

    Eilon

    Blog: http://weblogs.asp.net/LeftSlipper/
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-09-2006, 8:44 PM
    • Loading...
    • dawho9
    • Joined on 10-15-2003, 5:23 AM
    • Posts 44

    Checking to see if the problem I'm running into is the same issue.  When I add a validator to an accordian panel and place the validator outside the pane, it results in an error.  However, it seems to work when placed inside the accordian panel.

    Does anyone know if this the same problem?  If so, does anyone know a work around to make the validator work ourside the panel?

    Thanks,

    Richard
     

  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-19-2006, 8:38 AM
    • Loading...
    • npetroff
    • Joined on 06-22-2006, 1:10 PM
    • Penetanguishene
    • Posts 5

    I had the same issue with validation on a formview control inside an Update Panel.  I found that if the default view in the formview control was "ReadOnly" but there was not any data on the initial page load, that none of my client side validation would  work properly and the page would post back.

    My work around was:

     on page load "

     if page.IsPostback = False then

          FormView1.ChangeMode(Insert)

    end if.

    Then on page PreRender complete:

    if page.IsPostBack = False then

          FormView1.ChangeMode(ReadOnly)

    End if.

     

    This worked perfectly.  It's a bit ghetto... but remember, we are working with a framework(ATLAS) that is still in development.

    Norm.

  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-23-2006, 12:52 PM
    • Loading...
    • Eilon
    • Joined on 06-26-2002, 6:14 PM
    • Redmond, WA
    • Posts 716
    • AspNetTeam

    Please check out the Atlas 1.0 beta with the updated validators. It should fix all these cases without any hacks.

    Thanks,

    Eilon

    Blog: http://weblogs.asp.net/LeftSlipper/
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-23-2006, 5:09 PM

    Yes it does work

    but if i use ValidatorCalloutExtender it is not working ,

    any idea how to use ValidatorCalloutExtender in this scenario? 

  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-23-2006, 9:35 PM
    • Loading...
    • Eilon
    • Joined on 06-26-2002, 6:14 PM
    • Redmond, WA
    • Posts 716
    • AspNetTeam

    I've forwarded the ValidatorCalloutExtender issue to the AJAX Toolkit guys.

    Thanks,

    Eilon

    Blog: http://weblogs.asp.net/LeftSlipper/
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    10-24-2006, 9:56 PM
    • Loading...
    • sburke_msft
    • Joined on 04-04-2006, 7:28 PM
    • Redmond, WA
    • Posts 770
    • AspNetTeam

    If it's in a templated control you need to force control creation before the script manager renders scripts.  This is a known issue with the ASP.NET AJAX beta and will be fixed in the next release.

     

    In the meantime, in you Page_Load do:

    object c = FormView1.Controls;

     

    And it should work.

    Don't forget, this posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    04-27-2007, 7:13 PM
    • Loading...
    • newbie06
    • Joined on 04-14-2006, 5:28 PM
    • Posts 345
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    04-27-2007, 11:06 PM

    The link doesn't work....

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: BUG: regular ASP.NET validation broken when a validator is placed inside an UpdatePanel

    04-27-2007, 11:08 PM

    Hey it's working now.!!!!

    Sometimes it gives the error like 404 Page not found..

    Sometimes it's working..Smile

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 1 of 1 (12 items)
Microsoft Communities
Page view counter