traceback:http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx
If you've used the Microsoft ASP.NET AJAX UpdatePanel control, there's a good chance you've hit the "Sys.WebForms.PageRequestManagerParserErrorException" error.
What's a PageRequestManagerParserErrorException?
The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server. Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often). Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts.
As I mentioned, this is rendered out using a special format that the JavaScript on the client can understand. If you mess with the format by rendering things outside of the render phase of the page, the format will be messed up. Perhaps the most common way to do this is to call Response.Write() during Page's Load event, which is something that page developers often do for debugging purposes.
The client ends up receiving a blob of data that it can't parse, so it gives up and shows you a PageRequestManagerParserErrorException. Here's an example of what the message contains:
---------------------------
Microsoft Internet Explorer
---------------------------
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'Hello, World!106|upd'.
---------------------------
OK
---------------------------
If you ask me, this error message is not all that bad. After all, I'm the one that made it :) The details indicate what was being parsed when it decided to give up. You can see the part of the text from my Response.Write(), and immediately after that is part of the special format I keep mentioning.
Why do I keeping getting a PageRequestManagerParserErrorException?
Well, chances are you're doing one of the things mentioned in the error message. Here are the most common reasons and why they don't work:
How do I avoid getting a PageRequestManagerParserErrorException?
To start with, don't do anything from the preceding list! Here's a matching list of how to avoid a given error (when possible):
Another way to avoid the parse error is to do a regular postback instead of an asynchronous postback. For example, if you have a button that absolutely must do a Server.Transfer(), make it do regular postbacks. There are a number of ways of doing this:
Summary
I hope I've answered a lot of questions here and not angered too many of you. We're looking at ways to improve some of these situations in the next version of ASP.NET, but of course there are no guarantees. If you avoid changing the response stream, you're good to go. If you absolutely must change the response stream, simply don't do asynchronous postbacks.