Khilen
Khilen

Reputation: 1089

Gets Error while i write Response.write() on click event of button

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 '

Hi i have kept button in updatepanel and i am getting this error

Upvotes: 1

Views: 1671

Answers (3)

Alfishe
Alfishe

Reputation: 3680

More generic reason is that some firewalls/browser plugins can strip AJAX related HTTP header value X-MicrosoftAJAX and thus normal page rendering cycle is broken.

Detailed explanation was available in Telerik blog Blog post on Telerik site but seems due to company reorganization they lost blog service (hope that temporarily). So quote from Bing cache:

http://cc.bingj.com/cache.aspx?q=http%3a%2f%2fblogs.telerik.com%2fhristodeshev%2fposts%2f07-06-24%2ffirewalls_breaking_asp_net_ajax.aspx&d=4534636468308322&mkt=en-GB&setlang=en-US&w=8ZCg4pTc8CwOHTBDOYwjhsvWmFHYT0tM

Firewalls breaking ASP.NET AJAX! This one is serious and may bite you any time.

Yesterday Shaun posted this problem in our forums: he and his users were experiencing odd errors when requesting ASP.NET AJAX-based sites, and yes, that means RadControls "Prometheus" based ones as well. Partial rendering requests initiated by UpdatePanel controls failed with the cryptic message:

============== Sys.WebForms.PageRequestManagerParserErrorExeption: 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 '

Of course all that comes without any trace of Response.Write(), HttpModule, response filter or server-side tracing in his code. The horror, the horror...

Having the luxury of being a part of a team that has implemented a framework similar to ASP.NET AJAX, I noticed that something was making ASP.NET AJAX render the entire page and return it back to the browser even when the server code was supposed to be handling a partial rendering request. Note my emphasis (the bold part is the beginning of a normal HTML document):

============== Sys.WebForms.PageRequestManagerParserErrorExeption: 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 *****'

I believe the Watchguard guys should get the X-MicrosoftAjax header into their known headers list pretty quick. Until they do, please disable that setting. I think they are not the only firewall solutions provider that may have this problem. Are you behind a header-stripping firewall? Please post a comment below! I don't mean corporate solutions only -- personal firewalls can do that as well. The bigger list we have, the greater chance of sparing somebody a tough problem.

On the other hand, is there a good reason for a firewall to strip your HTTP request headers? All I can think of is the age-old sysadmin principle of "Disable all that your users don't need, and then go ahead and disable some more."

Upvotes: 0

Aristos
Aristos

Reputation: 66641

The updatePanel is an automatic way of ajax, and can not work with Response.Write() because is needs to render on memory what is going to send, and not pass from the page. The Respose.Write() send the output to the client directly, is like a direct output to the client page, but without having this page. So the Respose.Write() on updatePanel throw an exception.

Replace the Respose.Write() with probably a literal, and place inside the literal the output that you like to show.

Upvotes: 0

Samuel Neff
Samuel Neff

Reputation: 74909

You shouldn't use Response.Write in the event handler for a button. Really you shouldn't use Response.Write() at all unless you're handling ALL of the response generation manually (and then you might as well use an ashx instead of aspx).

One workaround is to place a literal control on the page where you want your text to be displayed and in the button click event set the value of the literal.

Upvotes: 1

Related Questions