The Orbit Notebook Software Architecture, Development and Design Thoughts

16Nov/100

Ugly Javascript Error when Downloading PDF Files (or other Response.Write files)

This past week, I had a creepy error hit me in an ASP.NET website that I inherited a few weeks ago.

Basically, the website allows you to click on a LinkButton to view a .PDF of a warranty's brochure.  When debugging the site in Firefox, nothing happened when I'd click the LinkButton.  And, I mean nothing.  Fortunately, the console in Firebug let me drill-in and view the details.  (IE also gave me the little "hazard sign" in the bottom left-hand corner, with the details)

Here's the error message:

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.

After doing some research, I found a pretty simple solution for the error.

I'm not going to go into specifics about what and why the error occurred (Eilon Lipton does that for me, here) but I will tell you that the basic explanation is that my LinkButton was inside an UpdatePanel, and rendering from UpdatePanels (asynchronous postbacks) can get a little squirrely.

So, how did I fix it?  Directly under the declaration of my UpdatePanel, I added a PostBackTrigger, and pointed it at my LinkButton.  Voila.  Problem solved.

Here's the code snippet:

...

Hopefully, this one saves you some time. Cheers.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.