Al Pascual



Geo RSS
Geo Twitter Timeline

Blogs I read

<December 2008>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

How to fix Sys.WebForms.PageRequestManagerParserErrorException in AJAX

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

Posted: Apr 26 2007, 11:25 PM by albert | with 52 comment(s)
Filed under: ,

Comments

Mark said:

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.
# April 30, 2007 12:42 PM

PohEe.com said:

It helps me alot. I spent 1 week to solve this problem. Finally got help from you :)
# May 8, 2007 4:41 AM

TrackBack said:

# May 8, 2007 11:03 AM

Ton said:

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!
# May 21, 2007 7:43 AM

krupsky said:

You are greate!!!!!! I spent one week to solve this problem, too.
var map = null; function GetMap() { map = new VEMap('myMap'); map.LoadMap(); } GetMap();
# August 25, 2007 7:12 AM

Tarantino said:

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();
# August 30, 2007 6:21 AM

Don Ebert said:

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.
# September 18, 2007 2:29 PM

adi alam said:

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

# October 9, 2007 11:21 PM

Sierra Mikain said:

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!

# October 18, 2007 2:43 PM

Manish Sharma said:

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

# October 24, 2007 5:21 AM

Michael Sivers said:

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!
# October 24, 2007 11:17 AM

Peraxel Märs, Sweden said:

Thanx. You are a life saver :)

# October 25, 2007 4:06 AM

Paul Whitworth said:

EnableEventValidation="false" worked for me! Ended several hours of frustration. THANKS!
# October 26, 2007 1:20 PM

Laurie Dickinson said:

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!

# November 4, 2007 10:24 PM

John Michael Alintano said:

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.
# November 6, 2007 2:33 AM

Hackin said:

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

# December 1, 2007 1:16 AM

sasan said:

EnableEventValidation="false" didn't work for me :(
# December 3, 2007 4:33 PM

poetical said:

if you use javascript move after the .
# December 11, 2007 10:33 AM

sambo said:

EnableEventValidation="false" didn't work for me too. Any idea?
# December 11, 2007 11:58 PM

Prasad said:

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 ????????
# December 16, 2007 10:10 AM

Dave said:

I just remembered to add the if (!IsPostBack) { ... around my session stuff in the page load Then it worked fine :-)
# December 20, 2007 9:55 AM

sajid said:

works on one page, but not on the other, I'm using master pages.
# December 24, 2007 9:33 AM

antuking_ulo said:

hey, i was able to solve this issue, i tried to add a postback trigger to my updatepanel...a single line of code....
# January 11, 2008 9:45 PM

foxmishy said:

you can try set like this ValidateRequest="false".eg
# January 15, 2008 4:18 AM

TrackBack said:

# January 16, 2008 2:50 PM

Paul Idusogie said:

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?
# January 21, 2008 3:58 PM

Reilly said:

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  

# February 7, 2008 10:45 AM

Fabio said:

thanks man.... EnableEventValidation="false" seems to work for me
# March 12, 2008 10:47 AM

Robert said:

THANK YOU! THANK YOU! THANK YOU! EnableEventValidation="false" works!
# March 27, 2008 6:26 PM

albert said:

Happy I could help.

# March 27, 2008 6:31 PM

Naveed said:

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.
# March 28, 2008 5:24 AM

Naveed said:

Thankyou. This solves my problem.

# March 28, 2008 5:42 AM

Jandoubi said:

All solutions seem not to work for me, can any one help me
# April 3, 2008 9:52 AM

viper said:

none of the solutions worked for me either, I need help! :(
# April 7, 2008 7:07 PM

Ben Sloan said:

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
# April 16, 2008 3:30 AM

Niladri said:

Great solution. You have made up my day! Thanks a looooot
# April 22, 2008 1:20 AM

Community Blogs said:

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

# April 23, 2008 2:46 AM

Moe Hashem said:

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
# April 23, 2008 7:21 PM

prasanth said:

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>  

# May 6, 2008 1:14 AM

Ivan said:

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.
# May 8, 2008 10:44 AM

DaveM said:

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?
# June 3, 2008 1:32 PM

Raj said:

Work fine  thnks

# June 12, 2008 8:28 AM

Debashis Nandi said:

Just use PostBackUrl prop example : -------- Enjoy!! Deb
# June 19, 2008 3:09 AM

Maisam Raza Lakhani said:

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

# July 1, 2008 9:54 AM

Matt said:

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); } });
# July 10, 2008 12:14 PM

m9525 said:

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?
# July 18, 2008 8:42 PM

Kaps said:

thanks a lot finnaly got where was the problem
# July 24, 2008 5:25 AM

Mithlesh said:

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

# August 14, 2008 2:26 AM

Hasan said:

thank you, it's help alot
# August 28, 2008 3:48 AM

Sam P said:

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!
# September 16, 2008 11:02 AM

Jatin Vyas said:

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.
# September 22, 2008 2:31 AM