MaintainScrollPositionOnPostback in Firefox 4.0

Unfortuantly, MaintainScrollPositionOnPostback stopped working in Firefox 4. This breaks our websites and needs to be fixed.

I’ve added the following to our App_Browsers folder in our .NET 4/IIS7 website:

<browsers>
  <browser id="Firefox4" parentID="Firefox">
      <identification>
          <capability name="majorversion" match="4" />
      </identification>
    
      <capabilities>
          <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
      </capabilities>
  </browser>  
</browsers>

Yet, support for MaintainScrollPositionOnPostback remains false for Firefox 4. I’ve also have tried changing several other properties and none of them are affecting the defaults for firefox. Please help.

Back in 2002 or so when I started doing this .NET thing they told us “this doesn’t really work, does bad stuff to web pages, should be avoided.” In 2011 we’ve got ajax to handle this pretty effectively, which is where I’d turn.

I’ve never been able to find a good fix for this. My only suggestion would be to use combination of divs and jQuery.

The original MaintainScrollPosition was the dodgy one. Some clever person came up with the idea of 2 hidden fields (xpos, ypos) who had a value of 0. On scroll script would update the values and as long as these hidden fields were asp.net controls then on postback they would retain any values. Your script would simply check if these hidden fields had values greater than 0 on page load and scroll to the position if so. I’m pretty sure asp.net (possibly version 2.0 and later) switched to this method from the earlier IE specific one that caused issues.

The upshot of all this is that you don’t need to rely on asp.net to do this if it stubbornly decides Firefox is not capable. Simply implement it yourself by manually adding the hidden fields and writing the script. A bit of hassle but can be easily re-used.

I think maybe I’ll just try to avoid MaintainScrollPositionOnPostback and make the site more AJAX enabled. And maybe the next framework update will include newer .browser files for the areas that need to keep the scroll position. I’d still love to figure out why I cannot get any changes I make to app_browsers to get picked up.