ASP.NET Ajax Error: Sys.WebForms.PageRequestManagerParserErrorException

左心房为你撑大大i 提交于 2019-11-27 21:56:35
splattne

There is an excellent blog entry by Eilon Lipton. It contains of lot of tips on how to avoid this error:

Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it

Read the comments too. There is a comment of somebody with the same problem: "I solved it changing server idle time of my app pool on IIS. It was only 5, so I incremented it and now works."

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

Most common reasons for that error:

  1. Calls to Response.Write():
  2. Response filters
  3. HttpModules
  4. Server trace is enabled
  5. Calls to Server.Transfer()

Probably there is an error occuring on post back. In this case, you can view the details about the error by adding a PostBackTrigger to your updatepanel and referencing the button which causes the problem:

    <asp:updatepanel ID="updatepanel1" runat="server">
        <Triggers>
            <asp:PostBackTrigger ControlID="button1" /> 
        </Triggers>
        <ContentTemplate>

        </ContentTemplate>
    </asp:updatepanel>

I had this happen to me and none of the causes on the list in the answer applied. I didn't find the root of the problem until I disabled my AJAX altogether. Discovered that the code was saving an object to the ViewState that contained an unserializable object. I made the object serializable and it started working again.

I solved this exact same problem removing the Content-Type: form the Custom HTTP Headers section in the HTTP Headers tab in IIS. This was breaking the encoding of the page and somehow it affected Ajax in general.

The Content-Type I had configured in IIS was setting the encoding to ISO-8859-1.

rahkim

This may be a little hacky, but it solved the issue for me. I didn't have any of the common reasons for the error, so I just put in this band-aid in the page load:

if (Session.SessionID == "")
{
    Page.Session.Add("SessionID", Session.SessionID);
}
Mathew M Mathew-Nest

Problem: Sys.WebForms.PageRequestManagerParserErrorException will occur when redirecting your page, lets say button click inside UpdatePanel in aspxAjax.

SOlution:

  1. Add a "GoTo" button in your aspx page where update panel is using and add it outside Update panel

  2. In your code assign ur just registered userID to session variable , say Session["UseridJustregistered"]=Id from DB or UsernameField

  3. Respose.Redirect("regSucces.aspx?urlid='" + Session["UseridJustregistered"] + "'");

  4. Check if Session["UseridJustregistered"] is null or not

This is OLD Classic ASP way which can solve our problem , by the time Microsoft find a solution we can tackle it this way.

Anuradha

I solved this same problem by removing mistakenly-nested UpdatePanels.

I finally solved my variant of this same problem. I was attempting to copy/move a selected value between 2 listboxes in a webform. In my case, I had to specifically call {listbox}.ClearSelection() prior performing the action the 2nd time around.

So obviously this problem/error message can occur for a multitude of reasons.

Change of the app pool FROM INTEGRATED to asp.net classic solved the problem for me.

In our case the issue was caused by a rewriting proxy on the way. The rewrite modified the content of the update panel response. But this response also contains original size. The rewriting mechanism cannot know that few bytes of the response actually contains original response size and it should also be modified.

The update panel response starts like this:

1|#||4|30502|updatePanel|pnlUpdate| ...

The 30502 is original size of the content which is being updated. Rewriting engine modifies the output, but the size stays unchanged => parser error exception.

I don't see a way how to overcome this issue from the client side. We would need to know how exactly was the content modified and then somehow change the size in the response before UpdatePanel ClientScript starts processing it.

I also got this error. The solution reported by "user1097991" solved it for a while (I was using not-serialized objects on viewstate)

But later the error returned again, now in a random fashion. After some search I got the answer: the viewstate was becoming too large and was been truncated. I disable some viewstates on grids and menus and the problem haven't shown again.

I found that my issue was related to a nul character being rendered in the databinding of a GridView. The expected length of the response wasn't matching the actual length of the response text which resulted in the error being thrown. Once I fixed the data in the database, I no longer got the error. The ultimate fix will be to sanitize the text getting rendered during the RowDataBound event.

Looking through the database, I couldn't see the bad data since SQL Server 2008 doesn't show the text if the nul character (Char(0)) is in the string. In the RowDataBound event of my GridView, I added code to throw an exception for any text that had special characters in it. This is how I found the record that contained the nul characters.

tl;dr - Check for nul characters in the rendered html.

Please also be aware that this can be caused by not properly html encoding what you may be rendering to the page through partial postbacks.

I had exactly the same error.

For me it was

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Missing in the httpModules section of web.config (.Net 3.5 app)

This error seems to may be related to many various things.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!