Wow! Finally! By chance I stumbled across another blog post on the web, where a solution (or temporary fix until something better turns up) to my ongoing PageRequestManagerParserErrorException problems.

Basically the problem is that on a page where I use the Microsoft AJAX.NET framework, I get intermittent popups when viewing the pages in Firefox. The popups contain the nice, short, concise 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. Details: Error parsing near ''"

Now I finally found someone who came up with a simple yet effective hack to mask/solve the problem. The solution involves adding some Javascript to your pages and then overriding the OnInitCompleted method on the server side.
Here's the JavaScript code:

<script type="text/javascript" language="javascript">
window.isFireFox = (navigator.userAgent.indexOf("Firefox") != -1);

        function OnPageLoad()

        function OnBeginRequest(sender, args)
                var delta = args.get_request().get_headers()['X-MicrosoftAjax'];    
                if(delta == 'Delta=true')    
                    var body = args.get_request().get_body() + 'X-MicrosoftAjax=' + encodeURIComponent('Delta=true');        


And here's what goes in your codebehind:

protected override void OnInitComplete(EventArgs e)
  #region Firefox Fix

  ScriptManager sm = ScriptManager.GetCurrent(this);
  if (IsPostBack && Request.Browser.Browser == "Firefox" &&
   sm != null &&
   sm.IsInAsyncPostBack == false &&
   Request.Form["X-MicrosoftAjax"] == "Delta=true")
      System.Reflection.BindingFlags.NonPublic |
      System.Reflection.BindingFlags.Instance).SetValue(sm, true);

Lo, and behold, it seems to work! Thanks to M. Bhaskar for the solution!

comments powered by Disqus