Sys.WebForms.PageRequestManagerParserErrorException @ MS Ajax

Spending a weeks to troubleshoot the "Sys.WebForms.PageRequestManagerParserErrorException" error in my company’s project.

 

Finally I found the workaround for it. Very easy, just disable the enableEventValidation on the ASPX page containing the UpdatePanel.

If this workaround doesn’t work for you, you should probably look @ Eilon Lipton’s Blog. Here is some of his findings:

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:

  1. Calls to Response.Write():
    By calling Response.Write() directly you are bypassing the normal rendering mechanism of ASP.NET controls. The bits you write are going straight out to the client without further processing (well, mostly…). This means that UpdatePanel can’t encode the data in its special format.

  2. Response filters:
    Similar to Response.Write(), response filters can change the rendering in such a way that the UpdatePanel won’t know.

  3. HttpModules:
    Again, the same deal as Response.Write() and response filters.

  4. Server trace is enabled:
    If I were going to implement trace again, I’d do it differently. Trace is effectively written out using Response.Write(), and as such messes up the special format that we use for UpdatePanel.

  5. Calls to Server.Transfer():
    Unfortunately, there’s no way to detect that Server.Transfer() was called. This means that UpdatePanel can’t do anything intelligent when someone calls Server.Transfer(). The response sent back to the client is the HTML markup from the page to which you transferred. Since its HTML and not the special format, it can’t be parsed, and you get the error.

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):

  1. Calls to Response.Write():
    Place an <asp:Label> or similar control on your page and set its Text property. The added benefit is that your pages will be valid HTML. When using Response.Write() you typically end up with pages that contain invalid markup.

  2. Response filters:
    The fix might just be to not use the filter. They’re not used very often anyway. If possible, filter things at the control level and not at the response level.

  3. HttpModules:
    Same as response filters.

  4. Server trace is enabled:
    Use some other form of tracing, such as writing to a log file, the Windows event log, or a custom mechanism.

  5. Calls to Server.Transfer():
    I’m not really sure why people use Server.Transfer() at all. Perhaps it’s a legacy thing from Classic ASP. I’d suggest using Response.Redirect() with query string parameters or cross-page posting.

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:

  1. The easiest is to simply place the button outside of any UpdatePanels. Unfortunately the layout of your page might not allow for this.

  2. Add a PostBackTrigger to your UpdatePanel that points at the button. This works great if the button is declared statically through markup on the page.

  3. Call ScriptManager.RegisterPostBackControl() and pass in the button in question. This is the best solution for controls that are added dynamically, such as those inside a repeating template.

Overall, I guess it is one of the bug in the latest MS Ajax 1.0. Hopefully they will fix it in the future release.

Tagged Under ( , , , )

4 Responses to “Sys.WebForms.PageRequestManagerParserErrorException @ MS Ajax

  • 1
    Bob Ross
    May 21st, 2007 22:01

    I am trying to use the Login Control to show a animation whilst logging in.

    Everytime I add the Onlogging event of the Login Control to the triggers of the updatepanel or register it via the script manager then I get this error.

    Is there anyway around this?

  • 2
    PohEe
    May 22nd, 2007 00:58

    During your post back, do you set any Response.write / Response filters / HttpModules / Calls to Server.Transfer()? IF yes, I suggest you to try other method while waiting for the bug fixed from Microsoft.

  • 3
    wheresaldo
    May 24th, 2007 04:02

    Hi PohEe,

    I’m having the same problem, I’m NOT using any Response.write / Response filters / HttpModules / Calls to Server.Transfer. I get the error when the page has been idle for more than 20 minutes and then I click a button within the UpdatePanel. I’m not using sessions, so I’m not sure what’s going on. Any ideas?

  • 4
    gutix
    March 5th, 2008 20:34

    Thanks a lot. EnableEventValidation=”false” works fine.

Leave a Reply