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.

  • Anonymous

    Thank you very much. You have saved me a ton of debugging time.

    Do you know yet what is causing this calamity?


  • Anonymous

    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.

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

  • Anonymous

    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.

  • sofrer

    In my case the problem was a compiler exception during the postback!

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

  • Ammar

    I don’t have Response.Write in my code, still I am getting this error. Any suggestion??

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

  • Newbie

    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.AddHeader(“content-disposition”, “attachment;filename=test.xls”);
    Response.Charset = “”;
    Response.ContentType = “application/vnd.xls”;
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    public override void VerifyRenderingInServerForm(Control control)

    do you have any suggestions? Thanks in advance!

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

  • Jeff

    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.

    Jeff Wasilauski, MCAD .NET, MCP

  • 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) ?

  • Hi, I’m getting the error when I upload the site to the live server. But on my developer machine everything is fine.

  • 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?

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

    The page works on my developer machine but not on the live server.

    Any thoughts ?

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

  • gsk

    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.


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

  • Yasser

    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

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

  • sid

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

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

  • Shaik Soofi

    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.

    [email protected]

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

  • Shaik Soofi

    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
    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 = “”
    Session(“ActiveTimer”) = “SCHEDULE”
    Session(“Sch”) = CType(DataList1.SelectedItem.FindControl(“lblName”), Label).Text
    Catch ex As Exception
    lblErr.Text = ex.Message.ToString
    End Try
    End Sub

    Private Sub ExportDataGrid()

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

    [email protected]

  • 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 Function
    function setSubmit() //btnSubmit under Contacts tab
    __doPostBack(‘btnSubmitClick’, ”);


    //Put at the bottom of aspx page.

  • Shalu

    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.

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

  • Jilani

    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 ‘

    can anyone tell me whats the reason?? its urgent

  • 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?

  • Jilani

    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

  • Jilani

    from my PC i m not getting it, but those are using they are getting this message

  • Jilani

    my client have “thin client environment”

  • 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?

  • Sue

    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.

  • 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

  • Jaydeep Mehta

    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.


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

  • Jaydeep Mehta

    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.


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

  • Jaydeep Mehta

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



    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.


  • Jaydeep Mehta

    re-trying to post the text.

    input type=”hidden” name=”__VIEWSTATE” id=”__VIEWSTATE” value=”/wEPDwUJLTMyNDQ5NDA0ZGT7Lr626C9G5ejl9snDB+mHauTUoA==”

    input type=”hidden” name=”__VIEWSTATE” id=”__VIEWSTATE” value=”/wEPDwUJLTMyNDQ5NDA0D2QWAgIDD2QWAgIDDxBkZBYBZmRkQisvExmhEc01Vb9BXamkVqrZdRI=”

    input type=”hidden” name=”__EVENTVALIDATION” id=”__EVENTVALIDATION” value=”/wEWCAK829GUBgKxjtSPCAKsoNW1AwKy4ZriBAK43dSADAKsoP21AwL06o7SBgKOq8SwCUC3G38EzIa1D1kIg3o2qZcjkiLg”

    input type=”hidden” name=”__EVENTVALIDATION” id=”__EVENTVALIDATION” value=”/wEWCAKGv5HdDgKxjtSPCAKsoNW1AwKy4ZriBAK43dSADAKsoP21AwL06o7SBgKOq8SwCUrUm8aFtE+gC++shy5t/RigOLJA”

  • rockspider

    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”, “”, 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?

  • 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?


    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,

  • ishan

    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

  • swolff

    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.

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

  • nikhil

    i have made user control for Export to Excell so tell me how to use above sollution in my functionality?

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