How to fix Sys.WebForms.PageRequestManagerParserErrorException in AJAX

written by Al on Thursday, April 26 2007

Most annoying issue with MS ASP.NET 2.0 Ajax  1.0 is the error Sys.WebForms.PageRequestManagerParserErrorException that will crash the web app. I found a great article from Eilon Lipton http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx to help you avoid the error.

You will encounter this issue when  mixing callbacks and postbacks, as callbacks do not use Response.Write and there is not complete Requests to the server.

This is a bug on the MS ASP.NET 2.0 AJAX 1.0, is not that you are doing something wrong, the framework cannot handle the request validation and the exception is thrown. I  found that you can catch the exception using the Script manager; information about it here: http://alpascual.com/blog/al/archive/2007/03/26/Code-Snip-_2200_Customizing-ScriptManager_2200_-to-detect-errors.aspx

Or better yet, you can disable the error by disabling the request validation. On top of the webform add: enableEventValidation="false"

 

Hope this helps somebody.

UPDATE: setting enableEventValidation does not fix the problem in all the cases.

Cheers

Al

 

Similar Posts

  1. Fixing the Validation of viewstate MAC failed error issue.
  2. Visual Studio 2008 surviving guide.
  3. Your First Silverlight 1.1 and Ajax Project

Comments

  • Mark Wisecarver on on 4.27.2007 at 6:09 AM

    Mark Wisecarver avatar

    That should help a lot of developers Al, thanks a bunch. ;-)

  • Mark on on 4.30.2007 at 12:42 PM

    Mark avatar

    thanks for this, I think it's complete BOBSHITE of MS to release AJAX with this problem. I've been going through my code for hours now.

  • PohEe.com on on 5.08.2007 at 4:41 AM

    PohEe.com avatar

    It helps me alot. I spent 1 week to solve this problem. Finally got help from you :)

  • Ton on on 5.21.2007 at 7:43 AM

    Ton avatar

    Strange. This problem suddenly started occurring on a piece of code that previously worked. I don't know what I've changed to trigger the problem. Adding enableEventValidation="false" fixed it. I hate problems like these!

  • krupsky on on 8.25.2007 at 7:12 AM

    krupsky avatar

    You are greate!!!!!! I spent one week to solve this problem, too.

    var map = null;

    function GetMap()

    {

    map = new VEMap('myMap');

    map.LoadMap();

    }

    GetMap();

  • Tarantino on on 8.30.2007 at 6:21 AM

    Tarantino avatar

    Done this solution, along with turning TRACE off, setting ValidateRequest=false and added a fake session variable in the page_load.

    Still no joy. Page which previously worked now falls over when doing a Response.Redirect on a button click(which is on an update panel)

    var map = null;

    function GetMap()

    {

    map = new VEMap('myMap');

    map.LoadMap();

    }

    GetMap();

  • Don Ebert on on 9.18.2007 at 2:29 PM

    Don Ebert avatar

    FYI

    I had the same issue and did everything nothing worked. Then I un-checked REMOVE UNKNOWN HEADERS via the firewall and bang, everything worked. It's possible every1 is looking into it to much.

  • adi alam on on 10.09.2007 at 11:21 PM

    adi alam avatar

    It doesnt help my problem, same error message still occur. I use User Web Control which is attached within an Iframe on aspx page (where I put the enableEventValidation="false"). Any idea guys?

    TIA,

    Alam

  • Sierra Mikain on on 10.18.2007 at 2:43 PM

    Sierra Mikain avatar

    I tried this and it didn't solve my problem, but thank goodness you mentioned this was AJAX's problem. I removed my hyperlink from the Update Panel and it worked perfectly. Thanks a lot!

  • Manish Sharma on on 10.24.2007 at 5:21 AM

    Manish Sharma avatar

    enableEventValidation="false"  fixes the problem.Itried it and it works.......so, thanks alot

  • Michael Sivers on on 10.24.2007 at 11:17 AM

    Michael Sivers avatar

    enableEventValidation="false" worked for me too! This exception only happend for me if I waited a few minutes before/between interacting with the controls which seemed strange? Anyway, seems to work fine now. Many thanks!

  • Peraxel Märs, Sweden on on 10.25.2007 at 4:06 AM

    Peraxel Märs, Sweden avatar

    Thanx. You are a life saver :)

  • Paul Whitworth on on 10.26.2007 at 1:20 PM

    Paul Whitworth avatar

    EnableEventValidation="false" worked for me! Ended several hours of frustration. THANKS!

  • Laurie Dickinson on on 11.04.2007 at 10:24 PM

    Laurie Dickinson avatar

    Using  EnableEventValidation="false" worked for me.  Thanks much!  I was getting this message and did not have Response.Write in my code or any of the other conditions that supposedly create this issue.  And to make it more interesting, it ran fine on my laptop, but broke only when I moved it onto the server for a user test to take place tomorrow morning.  I was banging my head against the wall, trying to get my code to work.  Thanks again for your help!

  • John Michael Alintano on on 11.06.2007 at 2:33 AM

    John Michael Alintano avatar

    IMHO, i suggest not to set EnableEventValidation to false as you may compromise the security of your code and the web that is running into it. I had experience a lot of errors regarding this issues and thinking to set the EnableEventValidation to false but I still try to find the most reliable solutions as much as possible. I believe it is something like a dirty trick, just because you are not able to solve the problem you just simply set it to false and that's it. I may not be an expert as other people here but as a programmer it is a good practice for all of us to solve a problem. Right?

    Anyway thanks for a good article. Happy coding everyone.

  • Hackin on on 12.01.2007 at 1:16 AM

    Hackin avatar

    EnableEventValidation="false" does NOT always get rid of this error...especially when you are clearly doing what you are not suppose to.  I needed to modify (Hack) the HTML post rendering to correct an undesirable feature in a 3rd party product.  To acheive this I had to remove portions of the html (post-render).  But, removing is bad, since the size the text/html for each update panel is tracked.  So to workaround, I could either adjust the text that tracks the size to the correct new size OR replace items with blank spaces (not by removing entirely).  Total hack...

  • sasan on on 12.03.2007 at 4:33 PM

    sasan avatar

    EnableEventValidation="false" didn't work for me :(

  • poetical on on 12.11.2007 at 10:33 AM

    poetical avatar

    if you use javascript move after the

    .

  • sambo on on 12.11.2007 at 11:58 PM

    sambo avatar

    EnableEventValidation="false" didn't work for me too.

    Any idea?

  • Prasad on on 12.16.2007 at 10:10 AM

    Prasad avatar

    HI !!

    EnableEventValidation worked for me :)

    Thanks !!!

    But is it safe to keep it false ???? Wont it be easy to manipulate postbacks ??? I mean unauthorised postbacks ????????

  • Dave on on 12.20.2007 at 9:55 AM

    Dave avatar

    I just remembered to add the

    if (!IsPostBack)

    {

    ... around my session stuff in the page load

    Then it worked fine :-)

  • sajid on on 12.24.2007 at 9:33 AM

    sajid avatar

    works on one page, but not on the other,

    I'm using master pages.

  • antuking_ulo on on 1.11.2008 at 9:45 PM

    antuking_ulo avatar

    hey, i was able to solve this issue, i tried to add a postback trigger to my updatepanel...a single line of code....

  • foxmishy on on 1.15.2008 at 4:18 AM

    foxmishy avatar

    you can try set like this ValidateRequest="false".eg

  • Paul Idusogie on on 1.21.2008 at 3:58 PM

    Paul Idusogie avatar

    I have the same problem this time as a result of a CAPTCHA control embedded in an updatepanel. Does CAPTCHA require the enableEventValidation setting be set to "true" in order to work.

    I also noticed when I removed the control it identified as responsible for the problem "... near | asp:AdRotator... it went away. Any ideas?

  • Reilly on on 2.07.2008 at 10:45 AM

    Reilly avatar

    Thanks!!

    "I  found that you can catch the exception using the Script manager; information about it here: alpascual.com/.../Code-Snip-_2200_Customizing-ScriptManager_2200_-to-detect-errors.aspx"

    This link solved the problem for me as it was infrequently occurring and I had already set enableEventValidation = FALSE  

  • Fabio on on 3.12.2008 at 10:47 AM

    Fabio avatar

    thanks man....

    EnableEventValidation="false" seems to work for me

  • Robert on on 3.27.2008 at 6:26 PM

    Robert avatar

    THANK YOU! THANK YOU! THANK YOU! EnableEventValidation="false" works!

  • albert on on 3.27.2008 at 6:31 PM

    albert avatar

    Happy I could help.

  • Naveed on on 3.28.2008 at 5:24 AM

    Naveed avatar

    Thanks alot. I did not spent a unit time to fix this problem. I just put this error message text in Google's search query text box and got your this article with solution.

  • Naveed on on 3.28.2008 at 5:42 AM

    Naveed avatar

    Thankyou. This solves my problem.

  • Jandoubi on on 4.03.2008 at 9:52 AM

    Jandoubi avatar

    All solutions seem not to work for me, can any one help me

  • viper on on 4.07.2008 at 7:07 PM

    viper avatar

    none of the solutions worked for me either, I need help! :(

  • Ben Sloan on on 4.16.2008 at 3:30 AM

    Ben Sloan avatar

    For me, I was not happy to disable enableEventValidation.

    I was getting this error message when I tried to set a session variable ("BuildingID") on the selectedindexchanged on a dropdownlist.

    I noticed that the problem only occured the first time this session variable got set in the application.

    To solve this problem, I put the following in Page_Load:

    If Not IsPostback Then

    StateManager.BuildingID = -1

    ' Custom class, does the same as Session("BuildingID") = -1

    End If

    This means that when I go to set the session variable in the SelectedIndexChanged of the dropdownlist, it is not the first time in the application the variable got set.

    This has solved my problem.

    Good luck,

    Regards,

    Ben

  • Niladri on on 4.22.2008 at 1:20 AM

    Niladri avatar

    Great solution. You have made up my day! Thanks a looooot

  • Moe Hashem on on 4.23.2008 at 7:21 PM

    Moe Hashem avatar

    Thanks for your time in putting this information together. Unfortunately, none of the ideas such as setting "EnableEventValidation = False" or "ValidateRequest = False" worked for me.

    I had a TabContainer with 7 TabPanels in it. I had the all the tabs surrounded with an UpdatePanel. Inside one of the panels was a section where our insurance brokers can login via 2 textboxes and a link button. This link button's event had to dynamically generate a form via a few "Response.Write" methods, which would in-turn pass the credentials from my .NET app to a Classic ASP app.

    The way I fixed this error is to add another update panel around the div that housed the textboxes and the link button, AND.....!!!! ADD a tag that allowed the link button to do a regular postback and not an asynchPostback....

    Here is the sample of what it looks like, in case you are interested:

    Thanks again for your time and I hope this helps somebody...!

    All the best,

    Moe

  • prasanth on on 5.06.2008 at 1:14 AM

    prasanth avatar

    SCRIPT TO OVERCOME 'Sys.WebForms.PageRequestManagerTimeoutException'

    ===================================================================

    <script type="text/javascript">

      Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args)

    {

          if (args.get_error() && args.get_error().name ===      'Sys.WebForms.PageRequestManagerTimeoutException') {

             //  alert('Caught a timeout!');

               // remember to set errorHandled = true to keep from getting a popup from the AJAX library itself

               args.set_errorHandled(true);

          }

       });

    </script>  

  • Ivan on on 5.08.2008 at 10:44 AM

    Ivan avatar

    This can be a firewall issue as well. Some firewalls stip the X-MicrosoftAjax header from the response.

    I'm still looking for a way to fix this issue, without resorting to calling each client's IT department to enable the header.

  • DaveM on on 6.03.2008 at 1:32 PM

    DaveM avatar

    Thanks very much. I spent two days on this stupid issue and I just tried the enableEventValidation="false" and it suddenly works. Isn't programming fun sometimes?

  • Raj on on 6.12.2008 at 8:28 AM

    Raj avatar

    Work fine  thnks

  • Debashis Nandi on on 6.19.2008 at 3:09 AM

    Debashis Nandi avatar

    Just use PostBackUrl prop

    example :

    --------

    Enjoy!!

    Deb

  • Maisam Raza Lakhani on on 7.01.2008 at 9:54 AM

    Maisam Raza Lakhani avatar

    Removing <customErrors defaultRedirect="ErrorPage.aspx" mode="RemoteOnly" /> from the web.config made it work for me ......

  • Matt on on 7.10.2008 at 12:14 PM

    Matt avatar

    Big thanks to Prasanth.

    Our problem was only slightly different. It occured when the authentication session had timed out. We were using Forms Authentication, which was expiring after 30 minutes. When the user tried to perform an action on an AJAX control after this timeout period the server was redirecting (the AJAX request) to the Login page, however the ScriptManager was unable to interpret this correctly.

    The only changes I've made to Prasanth's code is to display an alert message asking the user to reload the page from the navigation menu (I guess F5 might work in some situations) and the name of the Exception it is handling. Also note that is must appear after the closing ScriptManager tag:

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args)

    {

    if (args.get_error() && args.get_error().name === 'Sys.WebForms.PageRequestManagerParserErrorException') {

    alert('Your custom message here. Or comment line out to surpress.');

    // remember to set errorHandled = true to keep from getting a popup from the AJAX library itself

    args.set_errorHandled(true);

    }

    });

  • m9525 on on 7.18.2008 at 8:42 PM

    m9525 avatar

    Actually, none of them work for me. Not even the javascript thing because I don't have Sys.

    So... in the middle of the night, I simply increase the timeout for ScriptManager from default 90 seconds to something bigger, say 5 minutes?

  • Kaps on on 7.24.2008 at 5:25 AM

    Kaps avatar

    thanks a lot finnaly got where was the problem

  • Mithlesh on on 8.14.2008 at 2:26 AM

    Mithlesh avatar

    Hi,

      I was facing the same problem of 'Sys.WebForms.PageRequestManagerParserErrorException' i tried every thing i could and also searched the Net for the best solution ... i also tried using ValidateRequest="false"

    EnableEventValidation="false"

    but nothing worked for me....Actualy i was using response.Write() in my code with ajax update panel...which made all go wrong.Actualy i had to write the whole HTML of the page hence this helped me do tht.

    I made a function where i passed my page Response and in function made a parameter of HttpResponse to catch Response ...here is the code...

    private void responseWrite(HttpResponse response, string TxtHtml,string url)

    {

    response.Write(TxtHtml);

    response.Redirect(url);

    }

    I use response.Redirect to redirect it to same page which solves the problem.....the only thing is it reloads the page...bt in my case it was ok.

    Hope this may help u.....

  • Hasan on on 8.28.2008 at 3:48 AM

    Hasan avatar

    thank you, it's help alot

  • Sam P on on 9.16.2008 at 11:02 AM

    Sam P avatar

    I had this exception and it turned out to be because of how I was using a MultiView. The UpdatePanel was on one of the views in the MultiView and I was setting the active view in my page's OnPreLoad event. Moving the view-switching code into OnPreRender solved the problem. Rather bizarre, but I hope this helps someone!

  • Jatin Vyas on on 9.22.2008 at 2:31 AM

    Jatin Vyas avatar

    Hi,

    I am not using Ajax, I am just binary writing a RTF file but it is showing

    "Sys.WebForms.PageRequestManagerParserErrorException"

    error. I tried enableEventValidation="false" and ValidateRequest="false", but could not resolve this problem.

    I am writing

    Response.BinaryWrite(ByteArray)

    Please help me out.

Comments are closed

Options:

Size

Colors