SYS. webforms. pagerequestmanagerparsererrorexception

Source: Internet
Author: User
Tags parse error classic asp

SYS. webforms. pagerequestmanagerparsererrorexception-what it is and how to avoid it

If you 've used Microsoft ASP. NET Ajax Updatepanel Control, there's a good chance you 've got 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 handle T 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 processing 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 was Ed from the server cocould not be parsed. common causes for this error are when the response is modified by cballs to response. write (), response filters, httpmodules, or server trace is enabled.

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:

  1. Callto 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 required tively written out using response. write (), and as such messes up the special format that we use for updatepanel.
  5. Callto 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 callserver. 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. callto response. write ():
      place an 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 mechanic.
    5. callto 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.

Summary

I hope I 've answered a lot of questions here and not angered too quota of you. we're 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.

Details: Error parsing near 'hello, world! 106 | UPD '.
---------------------------
OK
---------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.