How to fix Sys.WebForms.PageRequestManagerParserErrorException in AJAX

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

Comments

Mark Wisecarver said on 4.27.2007 at 6:09 AM

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


Mark said on 4.30.2007 at 12:42 PM

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 said on 5.08.2007 at 4:41 AM

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


TrackBack said on 5.08.2007 at 11:03 AM


Ton said on 5.21.2007 at 7:43 AM

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 said on 8.25.2007 at 7:12 AM

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 said on 8.30.2007 at 6:21 AM

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 said on 9.18.2007 at 2:29 PM

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 said on 10.09.2007 at 11:21 PM

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 said on 10.18.2007 at 2:43 PM

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 said on 10.24.2007 at 5:21 AM

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


Michael Sivers said on 10.24.2007 at 11:17 AM

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 said on 10.25.2007 at 4:06 AM

Thanx. You are a life saver :)


Paul Whitworth said on 10.26.2007 at 1:20 PM

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


Laurie Dickinson said on 11.04.2007 at 10:24 PM

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 said on 11.06.2007 at 2:33 AM

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 said on 12.01.2007 at 1:16 AM

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 said on 12.03.2007 at 4:33 PM

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


poetical said on 12.11.2007 at 10:33 AM

if you use javascript move after the

.


sambo said on 12.11.2007 at 11:58 PM

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

Any idea?


Prasad said on 12.16.2007 at 10:10 AM

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 said on 12.20.2007 at 9:55 AM

I just remembered to add the

if (!IsPostBack)

{

... around my session stuff in the page load

Then it worked fine :-)


sajid said on 12.24.2007 at 9:33 AM

works on one page, but not on the other,

I'm using master pages.


antuking_ulo said on 1.11.2008 at 9:45 PM

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


foxmishy said on 1.15.2008 at 4:18 AM

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


TrackBack said on 1.16.2008 at 2:50 PM


Paul Idusogie said on 1.21.2008 at 3:58 PM

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 said on 2.07.2008 at 10:45 AM

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 said on 3.12.2008 at 10:47 AM

thanks man....

EnableEventValidation="false" seems to work for me


Robert said on 3.27.2008 at 6:26 PM

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


albert said on 3.27.2008 at 6:31 PM

Happy I could help.


Naveed said on 3.28.2008 at 5:24 AM

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 said on 3.28.2008 at 5:42 AM

Thankyou. This solves my problem.


Jandoubi said on 4.03.2008 at 9:52 AM

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


viper said on 4.07.2008 at 7:07 PM

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


Ben Sloan said on 4.16.2008 at 3:30 AM

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 said on 4.22.2008 at 1:20 AM

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


Community Blogs said on 4.23.2008 at 2:46 AM

Last year I wrote a fix for AJAX 1.0 on my old blog, looks like many people found it helpful, I wanted


Moe Hashem said on 4.23.2008 at 7:21 PM

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 said on 5.06.2008 at 1:14 AM

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 said on 5.08.2008 at 10:44 AM

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 said on 6.03.2008 at 1:32 PM

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 said on 6.12.2008 at 8:28 AM

Work fine  thnks


Debashis Nandi said on 6.19.2008 at 3:09 AM

Just use PostBackUrl prop

example :

--------

Enjoy!!

Deb


Maisam Raza Lakhani said on 7.01.2008 at 9:54 AM

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


Matt said on 7.10.2008 at 12:14 PM

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 said on 7.18.2008 at 8:42 PM

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 said on 7.24.2008 at 5:25 AM

thanks a lot finnaly got where was the problem


Mithlesh said on 8.14.2008 at 2:26 AM

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 said on 8.28.2008 at 3:48 AM

thank you, it's help alot


Sam P said on 9.16.2008 at 11:02 AM

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 said on 9.22.2008 at 2:31 AM

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.


How to switch content page? | keyongtech said on 1.18.2009 at 11:47 AM

Pingback from  How to switch content page? | keyongtech