6

MaintainScrollPositionOnPostback = true

its working with IE but not with mozilla(version 9)

suggest another way of maintaining scroll position that is browser independent..

thanxx

Ravi
  • 95
  • 1
  • 1
  • 8

2 Answers2

11

Found the answer here:

http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx

and here:

https://web.archive.org/web/20211020140248/https://www.4guysfromrolla.com/articles/111704-1.aspx

Let me know if it works out for you!


EDIT

Since I just had link answers I am actually just going to paste the code snippets here in case those links disappear:

From http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx:

<script type="text/javascript">
    var xPos, yPos;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        xPos = $get('scrollDiv').scrollLeft;
        yPos = $get('scrollDiv').scrollTop;
    }
    function EndRequestHandler(sender, args) {
        $get('scrollDiv').scrollLeft = xPos;
        $get('scrollDiv').scrollTop = yPos;
    }
</script>

From: https://web.archive.org/web/20211020140248/https://www.4guysfromrolla.com/articles/111704-1.aspx

<script language = "javascript">

    function sstchur_SmartScroller_GetCoords()
    {
        var scrollX, scrollY;

        if (document.all)
        {
            if (!document.documentElement.scrollLeft)
                scrollX = document.body.scrollLeft;
            else
                scrollX = document.documentElement.scrollLeft;

            if (!document.documentElement.scrollTop)
                scrollY = document.body.scrollTop;
            else
                scrollY = document.documentElement.scrollTop;
        }   
        else
        {
            scrollX = window.pageXOffset;
            scrollY = window.pageYOffset;
        }

        document.forms[formID].xCoordHolder.value = scrollX;
        document.forms[formID].yCoordHolder.value = scrollY;
    }

    function sstchur_SmartScroller_Scroll()
    {
        var x = document.forms[formID].xCoordHolder.value;
        var y = document.formsformID].yCoordHolder.value;
        window.scrollTo(x, y);
    }

    window.onload = sstchur_SmartScroller_Scroll;
    window.onscroll = sstchur_SmartScroller_GetCoords;
    window.onkeypress = sstchur_SmartScroller_GetCoords;
    window.onclick = sstchur_SmartScroller_GetCoords;

<script>

All the credit to the guys that worked hard on these answers.

jacqijvv
  • 870
  • 6
  • 17
  • Thanks for marking it as an answer, can you please just mark the answer as useful by clicking on the up arrow on the upper left side of the answer to give me some credit. Thanks :-) – jacqijvv Mar 09 '12 at 06:08
  • sorry i cant do that my reputation is below 15.. :( – Ravi Mar 09 '12 at 17:29
  • Can someone show me how to implement the first one? I am having troubles getting it to work correctly. Many Thanks! – JSON Jun 28 '16 at 18:50
0

I just ran into the same problem on a legacy code base. Updating the .NET Framework from 3.5 to 4.7 cleared it up for me.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299