PageRequestManagerParserErrorException

Geschreven door Steven
feb
21

Lately I’ve been using ASP.NET Ajax more and more, especially the UpdatePanel controls. At some point in time we came across the error mentioned in the title, the PageRequestManagerParserErrorException. After some internet searching we found out what the error meant, seeing as how it is quite the cryptic one if you ask me. As Eilon Lipton notes in his blog about this error, it is caused by the following:

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

As is shown by the amount of comments on that blog article it’s an error that could’ve been caused by lots of things and had just as many solutions. None of which (as always) worked in our case. What differentiated our error from most of the others was the fact that the page stopped parsing after the “<!DOCTYPE html PUB” piece of code. Some people noted the same error including the same line that stopped the parsing process.

Eventually, we found out what was causing this error to appear and it turned out to be as simple as it could’ve been. The piece of code running on the update was throwing an exception, which the UpdatePanel somehow choked on. The server returned the basic ASP.NET error page (hence the doctype piece of info) which the UpdatePanel caught and it was never shown on the website. Fixing the original exception also fixed the javascript error.

We did however implement a method that would stop the UpdatePanel from choking on the error page being returned. On the page that contains the AJAX ScriptManager control we implemented the ASyncPostbackError event of the ScriptManager and handled the Exception appropriately.

[vbnet]
Protected Sub ScriptManager_AsyncPostBackError(ByVal sender As Object, ByVal e As System.Web.UI.AsyncPostBackErrorEventArgs) Handles ScriptManager.AsyncPostBackError
‘ Handle e.Exception here
End Sub
[/vbnet]

Plaats op Twitter Plaats op Facebook Print deze post