Sys.WebForms.PageRequestManagerParserErrorException
Posted by: Eran Sandler, in AJAX.NET, ASP.NET“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.”

Have you ever got this kind of error when you are doing an Async postback using AJAX.NET (starting from Beta 2 if I’m not mistaken and going all the way to the current RC1 – at least at the time of writing this post) ?
It seems the newer versions of AJAX.NET really hates having “Response.Write” being called while doing an Async postback. It changes the response a bit causing it a hard time extracting the changed values and updating the changes using JavaScript on the client side.
If you get this error go through your page and all the controls in it (including controls within controls) and make sure you don’t have a “Response.Write” in the markup page.
Having “Response.Write” in the code behind in an event that is fired on an Async postback like Page_Load, Page_Render or the handler that handles that exact event can cause the same problem.
If you must use “Response.Write” you can get a similar solution by using a Label control and update it instead of using “Response.Write“.
If you use “Response.Write” in markup pages (ASPX or ASCX) replace them with either the “=” syntax (<% = MyProperty %>) or use the same solution mentioned above, adding a Label control and updating it in the code behind.








Entries (RSS)
January 4th, 2007 at 5:48 am
Thank you very much. You have saved me a ton of debugging time.
Do you know yet what is causing this calamity?
Thanks
January 4th, 2007 at 8:40 am
Another option for fixing this is to use a LiteralControl and add the control to the page during rendering. That worked better for me since I could keep everything in code.
January 4th, 2007 at 4:46 pm
To the first anonymous reader: Thanks for reading the blog
. In regards to what causes this behavior, without further Reflector digging (or just having the code) I cannot say for sure, but it seems like its either an implementation bug or an implementation problem/difficulty due to other behaviors.
The second anonymous reader:
Thanks for sharing another tip. Using the LiteralControl is also a good way of doing that.
January 5th, 2007 at 10:28 pm
Anyone know if a fix for this is forthcoming (seems like it wasn’t an issue pre-beta2)?
All the (MANY) pages I’m working with inherit from a base class that has several HTMLTextWriter.Write*() calls that contribute to this problem, so a fix would be nice. TIA.
February 4th, 2007 at 3:24 am
In my case the problem was a compiler exception during the postback!
February 4th, 2007 at 11:22 am
sofrer, it’s good to know another cause for this problem!
In general, there are various occasions that may lead to this problem if the post back will return a complete post instead of an async one.
February 8th, 2007 at 5:41 pm
I don’t have Response.Write in my code, still I am getting this error. Any suggestion??
February 8th, 2007 at 6:22 pm
Ammar, according to the error that is reported you may have other things that might be causing the post back merge to freak out.
Check that you don’t have various 3rd party HttpHandler or HttpModules that might touch the response.
Also, I’ve seen that in some weird cases, having the following syntax in the ASPX page itself can cause the problem:
< % = this.SomeProperty %>
Did you also check that you don’t have calls to Response.Write in your ASPX/ASCX files? I would do a grep on all of the code (*.cs;*.vb;*.aspx;*.ascx) and check for Response.Write just to verify.
February 13th, 2007 at 8:58 am
Hi, I’m a newbie and I am receiving the same error message when I want to process a grid to excel so that they can download the grid as excel file. Here’s the code I’m using:
protected void btnExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader(“content-disposition”, “attachment;filename=test.xls”);
Response.Charset = “”;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = “application/vnd.xls”;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
grdData.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
do you have any suggestions? Thanks in advance!
February 13th, 2007 at 10:16 am
Newbie, are you doing this in an async postback?
The problem is exactly what I said, you are using Response.Write which freaks out (sometimes) the AJAX.NET framework in charge of merging the result HTML back into the page.
I would suggest you to make sure that the “btnExcel” button is not marked in any of your update panels as an AsyncPostback Trigger. This will ensure that pressing on it will perform a full postback and will avoid these issues.
March 8th, 2007 at 4:07 am
I’m getting the same error when asynchronously calling the gridview rowCommand. The odd thing is, the error only occurs during the first asynchronous postback. After I clear the error alert, the functionality works perfectly. I don’t have response.write() in the code or codebehind, I disabled tracing in the web.config, and the only httpModule I have is the only below in the web.config file:
I have also tried removing the above code, but the first postback always contains the Sys.WebForms.PageRequestManagerParserErrorException error.
Any help would be appreciated.
Thanks,
Jeff Wasilauski, MCAD .NET, MCP
C#/VB.NET-WEB DEVELOPMENT
March 8th, 2007 at 9:08 am
Jeff, do you happen to have any 3rd party control that are not part of ASP.NET.
For example, implementing an ITemplate on a column or things like that?
I cannot see the httpModule you have since you pasted the XML from your web.config and WordPress (this blog’s blog engine) thought it was illegal. Can you just copy the name of the http module and its fully qualified name (full namespace, class name and assembly name) ?
March 8th, 2007 at 5:42 pm
Hi, I’m getting the error when I upload the site to the live server. But on my developer machine everything is fine.
March 8th, 2007 at 5:54 pm
Hi James,
I had the same problem, when I got this error it was only when I deployed it on our staging environment (and of course, it happened on the production environment as well).
Have you tried the various things I’ve talked about in the post?
Have you checked there are no Response.Write in the code (not even in the aspx/ascx) and not in other controls that are placed on these pages?
May 2nd, 2007 at 2:20 pm
Hi Eran,
I’ve checked my code and I have no response.write commands in my code.
I have uploaded a very simple test page to: http://www.thefrogsystem.com/uat/ajaxtest.aspx
The page works on my developer machine but not on the live server.
Any thoughts ?
May 2nd, 2007 at 2:51 pm
James, it seems that your test is working.
I suggest that you look into other 3rd party control that you use (if you use) and see if they perform a response.write somewhere.
Also, the syntax of <% %> can also cause, in some cases this error.
May 3rd, 2007 at 12:34 am
Its really good update.
Is it possible to avoid this error using the Response.write. My istuation is that i have to use an existing component which renders the HTML to build a menu component based on lot of business conditions. when i inherit the existing component which does the Response.write it throws the same error. Its not possible to put a label control for that.
Thanks…
May 3rd, 2007 at 10:56 am
gsk, you have a problem and you’ll probably need to get the source of the 3rd party component or consider using another one.
If you must use it, you’ll need to use it outside of the UpdatePanel and hope that you can get client side access to it.
Also, check if the vendor of that component is willing to fix it. It’s a very quick fix.
October 30th, 2007 at 3:54 pm
i too got the same error but i need response.write to be inthe code coz it writes java script into it like
Response.Write(@” function call{alert(‘Project Name is mandatory and can not be left blank’);}”);
can anyone give me the solution to this
October 31st, 2007 at 11:28 am
There are various ways you can make this without the need to do a response.write.
For example, make your function something more static that is specifically inside your ASPX page or ASCX control and in the right place perform the call.
Another technique to overcome this is to use a LiteralControl and put all of this inside of it instead of using Response.Write.
January 8th, 2008 at 4:01 pm
In My case i have a problem with the existing javascript attributes that are added in my page,
If the button click causes a javascript to pop up an alert, this error exception comes up, otherwise it works perfect…
Anybody has a ny solution??
January 16th, 2008 at 2:55 am
sid, are you sure this is the exact same error? Technically the code in AJAX.NET that throws this error is the code the tries to merge the delta HTML that was sent by the server due to a partial rendering request.
The only way that I can think of that can generate this when you click on the button and execute your javascript is this button also actually performs a postback and since you are in partial rendering mode it executes an async request that eventually triggers this error.
Try making sure that you do not auto postback from a click on that button or use a simple input type=button instead of an asp:button control.
May 27th, 2008 at 10:19 am
I can access the web application from localhost. When i connect with external IP address I got the following errors?
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’
<!DOCTYPE html PUB’.
Can u resolve this?
Thanks in advance.
soofimra@gmail.com
May 27th, 2008 at 4:23 pm
Hello Shaik Soofi,
There are a number of factors which can lead to the error you are seeing now.
Have you tried to do some of the suggestion I have made above? There are also a couple of suggestions in the comments of this post.
May 28th, 2008 at 9:49 am
I found out response.write in my web application. But these appln done by my colleagues. Totally I am newbie to VB.Net. and also Its very huge web application. I dont know how to change response.wrte to others. Below i gave my coding. File name is Report.aspx.vb
Protected Sub btnimgPrint_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnimgPrint.Click
Response.Write(“window.open(‘PrintActivity.aspx’,'_blank’);”)
End Sub
Protected Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
‘ Session(“ActiveTimer”) = CType(DataList1.Item.FindControl(“lblName”), Label).Text
lblErr.Text = “”
Try
Session(“ActiveTimer”) = “SCHEDULE”
Session(“Sch”) = CType(DataList1.SelectedItem.FindControl(“lblName”), Label).Text
Response.Write(“window.close()”)
Catch ex As Exception
lblErr.Text = ex.Message.ToString
End Try
End Sub
Private Sub ExportDataGrid()
Try
Response.ClearContent()
Response.AddHeader(“content-disposition”, “attachment; filename=MyExcelFile.xls”)
Response.ContentType = “application/excel”
Dim sw As System.IO.StringWriter = New System.IO.StringWriter
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
GridView3.RenderControl(htw)
Response.Write(sw.ToString)
Response.End()
Catch ex As Exception
End Try
End Sub
Pls give coding solution to this for how to change response.write.
Any help would be appreciated.
Thanks in advance.
soofimra@gmail.com
June 30th, 2008 at 4:03 am
One of things I had to do with buttons within ScriptManager is to call javascript functions to trigger the event.
//Code Behind
btnSubmit.Attributes.Add(“onclick”, “setSubmit();”);
//Javascript
Javascript Function
function setSubmit() //btnSubmit under Contacts tab
{
__doPostBack(‘btnSubmitClick’, ”);
}
//Put at the bottom of aspx page.
August 18th, 2008 at 4:33 pm
I ahd the the same problem and I using the response.write in ascx page to create the left menu please let me know whta’s the solution ofr this problem. It’s very urgent.
August 18th, 2008 at 5:24 pm
Shalu, if you are suing Response.Write than stop using it. Its part of what makes the problems. Use a Label instead and put a value inside the label.
August 23rd, 2008 at 11:31 am
hi, in my site its not showing but my client getting this message they got “thin Client Environment”
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 ‘
<!DOCTYPE HTML PUB’.
can anyone tell me whats the reason?? its urgent
August 23rd, 2008 at 1:47 pm
Jilani,
Have you tried to do some of the things I’ve suggested above? Have you checked that you are not using Response.Write in places where you return results through an async postback of an update panel?
August 23rd, 2008 at 2:22 pm
hi Eran Sandler
Thanks for reply, yes i checked i dont have any code like Response.Write instaed of it i have used” private void RedirectTo(string url)
{
//url is in pattern “~myblog/mypage.aspx”
string redirectURL = Page.ResolveClientUrl(url);
string script = “window.location = ‘” + redirectURL + “‘;”;
ScriptManager.RegisterStartupScript(this, typeof (Page), “RedirectTo”, script, true);
}
”
but same things happening, any idea buddy. thanks
August 23rd, 2008 at 2:26 pm
from my PC i m not getting it, but those are using they are getting this message
August 25th, 2008 at 7:54 am
my client have “thin client environment”
August 25th, 2008 at 8:01 am
Jilani, by “Thin Client” I’m assuming its a web browser.
Is there a chance that you have a user control on that page that users Response.Write without your knowledge?
September 5th, 2008 at 8:08 am
Hi Eran,
I m usiong Response.Redirect() on my page and getting the same error. Please suggest what do you mean by saying to use label or literal controls.
September 6th, 2008 at 9:43 am
Sue, if you use Response.Redirect as part of an async request (part of an UpdatePanel), in some situations you might get this error. I suggest that in the Response.Redirect you won’t use an UpdatePanel
September 22nd, 2008 at 11:41 pm
I have removed \ commented all form of response.write and response.xx commands. Thought I am getting this error. with “details” error parsing near ‘yBuilder |
Please suggest.
thanks
Jaydeep
September 23rd, 2008 at 10:02 am
You might still have some kind of a 3rd party control that you are using and is using Response.Write.
Also, if you have places in your ASPX page or ASCX control that uses the format of < % = SomeVariable %> its actually being translated to Response.Write(SomeVariable) so you might want to check these things as well.
September 25th, 2008 at 1:44 am
Thanks Eran for the reply. I removed all the third party controls. Infact, I made a hello-world type program with only dropdownlist in the page. Even after that the Asyncpostback doesnt work.
1. It works when I host the application on IIS
2. We have our own hosting platform which is a wrapper on http.sys. The application doesnt run on this. and shoots the error dialog box that is the topic of this discussion page. Our platform is build using .net 2.0.
We couldnt catch the dialog box in debugger. Please let me know any help or how can dig into this.
thanks
September 25th, 2008 at 10:49 am
Jaydeep,
If it works on normal IIS and w3wp (or aspnet_wp on XP or Windows 2000) process than I might suspect it has something to do with your own hosting platform.
Essentially, when you have an async postback, ASP.NET renders the whole page but sends only the delta between the original render and the new render.
On the client side, AJAX.NET will take the delta sent from the server and will try to merge it using JavaScript DOM back to the page. When that merge fails the error you are getting occurs.
What I suggest you do is this:
1) Take your hello-world app and run it in both IIS and your hosting platform.
2) In both cases use Fiddler or even Ethereal to capture the exact response sent back from the server to the async request.
3) Do a binary compare to make sure there are no hidden characters that differ from the two outputs.
If you find a difference between both outputs, it means that something in your hosting platform is the problem.
September 26th, 2008 at 1:20 am
I can clearly see the difference in the view source of the two hosting output.
I am listing them below copied from filecomparer (windiff) the line above is the one from our hosting platform and the below one is from IIS (which works fine).
1)
2)
I talked to the developer who worked on the hosting platform and we are not changing any thing from what is returned from http.sys.
Thanks
September 26th, 2008 at 2:03 am
re-trying to post the text.
1.
input type=”hidden” name=”__VIEWSTATE” id=”__VIEWSTATE” value=”/wEPDwUJLTMyNDQ5NDA0ZGT7Lr626C9G5ejl9snDB+mHauTUoA==”
input type=”hidden” name=”__VIEWSTATE” id=”__VIEWSTATE” value=”/wEPDwUJLTMyNDQ5NDA0D2QWAgIDD2QWAgIDDxBkZBYBZmRkQisvExmhEc01Vb9BXamkVqrZdRI=”
2.
input type=”hidden” name=”__EVENTVALIDATION” id=”__EVENTVALIDATION” value=”/wEWCAK829GUBgKxjtSPCAKsoNW1AwKy4ZriBAK43dSADAKsoP21AwL06o7SBgKOq8SwCUC3G38EzIa1D1kIg3o2qZcjkiLg”
input type=”hidden” name=”__EVENTVALIDATION” id=”__EVENTVALIDATION” value=”/wEWCAKGv5HdDgKxjtSPCAKsoNW1AwKy4ZriBAK43dSADAKsoP21AwL06o7SBgKOq8SwCUrUm8aFtE+gC++shy5t/RigOLJA”
December 22nd, 2008 at 1:53 pm
I have a similar problem. I dont use Response.Write.
The error I get is similar to the one described at the top of this page. Interestingly the error only applear in IE, not firefox. My entire site works OK until i click a button that runs either of the following code:
a) ScriptManager.RegisterStartupScript(this, typeof(string), “newwindow”, “window.open(http.externalurl.com)”, true);
b) myHyperlink.Attributes.Add(“onclick”, “myclientside-javascript-popupfuntion”);
c) in fact, the 3rd alternative does not run any code, it is a simple html anchor tag: go
All of these would pop up a new browser window as expected, the new window works fine (displays a secure website, i can log in fine), but when I close the popup and return to the original browser, all my navigation and pretty much the whole site stops working and pops up the error below (requires browser to be closed):
“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 <!DOCTYPE html PUB’.”
I thought the problem was HTTP handlers. I noticed an HTTPHANDLER in my web.config.
(I dont know why the handler is there and I do not have authority to remove it).
But when I tried without this handler I still get the same problem.
Any advice?
December 22nd, 2008 at 2:47 pm
rockspider, the main reason for this error is that the response that was sent back in the async post is not what the client side code of AJAX.NET expects.
As far as I can tell from your examples you don’t have any code that issues “Response.Write” where it shouldn’t.
However, I am concerned about examples “a” and “b”.
Example “a” might not work in async requests since you are requesting to register a startup script while you clearly have the page already rendered and working. If I under correctly, you want that upon a click a new window will be opened. I suggest that you simply render a javascript code block that performs your code instead of using “RegisterStartupScript”.
As for example “b” is the hyperlink you want to add an attribute to is inside an UpdatePanel?
January 6th, 2009 at 1:58 am
this error went away for me when i called HttpUtility.HtmlDecode method before i did a response.write.
Response.Write( System.Web.HttpUtility.HtmlDecode( string ) )
hope this helps,
later
March 24th, 2009 at 8:49 am
Hi, i am using ajax toolkits slider control, when the text_changed event is fired ( when the slider is moved) i generate some reports. i dont have any response.write in my code, i can generate this error if my session has expired. i logged in as admin, went to the page, moved the slider and it worked fine. if i clear browser history and then use the slider control then also the same error is generated. I want to change this error and say something like the session has expired or something. pls help
April 15th, 2009 at 8:25 pm
I was getting this same error message and after doing some searching around I tried adding EnableEventValidation=”False” to the top of my .aspx and this stopped the error message for me.
June 13th, 2009 at 5:27 pm
swolff, setting EnableEventValidation=False just silences this error because no validation happens. This can leave you open to various attacks that the event validation process have such as inject data that you didn’t plan on putting, etc.
September 15th, 2009 at 9:36 am
i have made user control for Export to Excell so tell me how to use above sollution in my functionality?
September 15th, 2009 at 9:50 am
One of the things, for example, that you can do is to check that in your .ascx file you don’t do “Response.Write”. This is just one of the causes for this issue.
Others found that disabling Event Validation also helps (though puts you at a bit of a risk).
October 22nd, 2009 at 6:31 pm
I have a user control that uses response.binary write. I need an updateprogress control to let the user know when the files are being process until the files are presented to be downloaded. Any suggestion on how to do this??? A label control can not help in this situation.
October 22nd, 2009 at 6:52 pm
Andre, if I understand correctly, its a bit more complicated than that since you want to inform the user when you finish the response.binarywrite, is this correct?
If you have a long running operation the best way to do that is using an async request, i.e. load a page, an async request will start the process itself. You might be able to flush updates as you go or update the status of the operation in a different place and send a request every X interval to a different URL that will check that same place.
A good way to do that might be to write to a temp location the status of your job, querying it from a different URL with a certain ID can show you the status.
Hope this helps.
December 21st, 2009 at 8:53 am
Hi same problem occur to me also i am not using response.write but else i am to write on label
and when i add asynchronouspostback in update panel for that event same error displayed again and again what should i hav to do
error is System.Webform.pagerequestmanagerparseexception
December 21st, 2009 at 8:56 am
I was getting this same error message and after doing some searching around I tried adding EnableEventValidation=”False” to the top of my .aspx and this stopped the error message for me.
December 21st, 2009 at 8:56 am
Nikks, you can use a Label Control or a Literal Control (which allows you to even put HTML, if I’m not mistaken). That way you can set the value of these control in the code behind and not use Response.Write that freaks out UpdatePanels.
January 15th, 2010 at 9:01 am
Eran Thank you very much
February 1st, 2010 at 1:15 am
I have the same problem and solved by placing the Button which contains response.redirect outside the updatepanel.
Hoping that might help others.
May 11th, 2010 at 2:31 pm
Thank you very much. this has solved my problem.
June 1st, 2010 at 5:09 pm
Thanks Eran for the post. I have a different kind of problem. I’ve hosted my application in a 2003 server(32 bit) and having this error message.
When I hosted this application in a different 2003 server (64 bit) the error message is not appearing. This arror message is not appearing too when I amrunning the application from development environment. Is there something I need to change in server configuration? Please respond.
June 1st, 2010 at 5:19 pm
Bhaskar Joardar, you might some httpModule or ISAPI filter install on that machine that causes the output to be changed a little bit, which may cause this issue.
June 20th, 2010 at 8:45 am
i just added a trigger and it worked fine