A couple of week ago a colleague of mine had a strange problem when running an ASP.NET WebForms application containing an UpdatePanel and a Response.Redirect inside a server side button click event handler. The same thing happened on my computer and yesterday I bumped into the same boring thing once more. I felt I had to find a proper solution to this!


The error in my development environment looks like this, but may look somewhat different on other boxes running different versions of Visual Studio and things like that:


 Error: Sys.WebForms.PageRequestManagerParserErrorException:
           The message received from the server could not be parsed. 

The error only occurred when running in the development environment through the Cassini WebDev server in Visual Studio so we left it there, not completely solved, by running the development site inside the local IIS. This worked fine but was still annoying.

Some investigation later made me realize that it must come from the redirect, e.g. when modifying the response stream in a similar “brutal” way, inside the event handler fired from inside an UpdatePanel. A simple google later and I bumped into this article: How to use Respone.Redirect inside An UpdatePanel in ASP.NET 2.0, written by Himanshu Sahu.

The solution to this problem is to add the following line of config inside the httpModules node in web.config:

<httpModules>
    <!-- ... -->
    <add name="ScriptModule"
       type="System.Web.Handlers.ScriptModule, System.Web.Extensions,
             Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <!-- ... -->
</httpModules>

and everything works great, even when running the Cassini WebDev server.

Thank you Himanshu Sahu!

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
© 2011 freddes.se Suffusion theme by Sayontan Sinha