Retain scroll position after postback

Last post 08-11-2009 1:25 PM by essie. 26 replies.

Sort Posts:

  • Re: Retain scroll position after postback

    04-08-2004, 12:20 PM
    • Participant
      1,424 point Participant
    • bt429
    • Member since 07-17-2003, 10:37 AM
    • Boulder, CO
    • Posts 290
    Jim,

    Thanks for the quick response - I'll look into that further. I'm not too familiar with DHTML but this gets me in the right direction. I certainly didn't mean that your solution was not good, as it is the one I went with!
  • Re: Retain scroll position after postback

    04-08-2004, 1:20 PM
    No problem at all, I didn't take it that way. I was mainly speaking to the "lurkers" on the thread.
    Jim


    MS MVP ASP.NET [VC++/MFC emeritus]


    Old Dog Learns New Tricks

    Preferred programming language: cuneiform on clay tablets
  • Re: Retain scroll position after postback

    04-14-2004, 5:29 PM
    • Member
      65 point Member
    • sampriti
    • Member since 06-18-2003, 1:17 PM
    • Posts 13
    Thank you!!!!!!
    I used this in my application and it works great.
  • Re: Retain scroll position after postback

    06-03-2006, 6:57 PM
    It's better to use SmartNavigation="true"...

    <%@ Page Language="vb" SmartNavigation="true" %>

    Big Smile
  • Re: Retain scroll position after postback

    08-03-2006, 9:55 AM
    • Member
      5 point Member
    • abjung7245
    • Member since 08-03-2006, 1:50 PM
    • Posts 1

      When I ran your user control code, I received java script error for object not found and it appears to be of the 'ltr.Text' objects as below.  Are these text boxes we need to put on page?  Thank you.

     

     

      ltrSF.Text = __SAVESCROLLY.ClientID;


       ltrSFX.Text = __SAVESCROLLX.ClientID;


       ltrRF.Text = __SAVESCROLLY.ClientID;


       ltrRFX.Text = __SAVESCROLLX.ClientID;

  • Re: Retain scroll position after postback

    09-04-2007, 5:58 PM
    • Member
      15 point Member
    • cjLopez
    • Member since 08-07-2007, 8:53 PM
    • Posts 29

    Yo dude, pretty nice trick, i was looking  how to avoid that the post back messed around with my page scroll and this did the trick, and pretty simple to implement, thank dude

  • Re: Retain scroll position after postback

    12-19-2007, 10:27 AM
    • Member
      2 point Member
    • Kiran_2007
    • Member since 12-19-2007, 3:24 PM
    • Posts 1

    It works great !! but after I included the savescroll.js file on my asp.net page, menu on the page is not working please advise. 

    JS Code for to build the menu on the page

    *************************************************************************************************************

    function StartUp()

    {

    StartList();

    ContentSize();

    }

    //From http://www.alistapart.com [Suckerfish menu]

    StartList = function() {if (document.all&&document.getElementById) {

    navRoot = document.getElementById("nav");

    for (i=0; i<navRoot.childNodes.length; i++) {

    node = navRoot.childNodes[i];

    if (node.nodeName=="LI") {

    node.onmouseover=function() {this.className+=" over";

    }

    node.onmouseout=function() {

    this.className=this.className.replace(" over", "");

    }

    }

    }

    }

    }

    //From: http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16

    function ContentSize()

    {

    var myWidth = 0, myHeight = 0;if( typeof( window.innerWidth ) == 'number' )

    {

    //Non-IE

    myWidth = window.innerWidth;

    myHeight = window.innerHeight;

    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'

    myWidth = document.documentElement.clientWidth;

    myHeight = document.documentElement.clientHeight;

    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible

    myWidth = document.body.clientWidth;

    myHeight = document.body.clientHeight;

    }
    else {

    //Everything else

    myWidth = document.body.clientWidth;

    myHeight = document.body.clientHeight;

    }

     

    var mySizeH = 0;

    var mySizeW = 0;

    var minSizeH = 99;

    var minSizeW = 10;

    if ( (myHeight - minSizeH) <= 0 )

    {

    mySizeH = 1;

    document.getElementById('content').style.display = 'none';

    }
    else {

    mySizeH = ( myHeight - minSizeH );

    document.getElementById('content').style.display = 'block';

    }

    if ( (myWidth - minSizeW) <= 0 )

    {

    mySizeW = 1;

    document.getElementById('content').style.display = 'none';

    }
    else {

    mySizeW = ( myWidth - minSizeW );

    document.getElementById('content').style.display = 'block';

    }

    document.getElementById('content').style.height = mySizeH;

    //document.getElementById('content').style.width = mySizeW;

    }

    window.onresize = ContentSize;

    window.onload=StartUp;

    *************************************************************************************************************

    Thank you,

    K

  • Re: Retain scroll position after postback

    06-01-2009, 9:43 PM
    • Member
      8 point Member
    • jeeshenlee
    • Member since 05-19-2009, 12:28 PM
    • Posts 16

    Hi All,

     I used a simple trick in my DataGrid_SelectedIndexChanged to maintain the visibility of the selected item after postback. Here the trick (Setting the focus of the selected record/row)

     

        Protected Sub gvNew_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvNew.SelectedIndexChanged
            Dim selectedIndex As Integer
            selectedIndex = gvNew.SelectedIndex
            gvNew.Rows(selectedIndex).Focus()
    
            dvRoom.PageIndex = selectedIndex
            dvRoom.DataBind()
        End Sub

     It's not as neat as the javascript solution, but well, it works on all browser. :)

    Thanks.

    Regards,

    JeeShen Lee

  • Re: Retain scroll position after postback

    06-12-2009, 3:21 PM
    • All-Star
      31,329 point All-Star
    • Naom
    • Member since 12-31-2007, 7:08 PM
    • Wisconsin
    • Posts 6,927

     The last solution is for Grids, I think (haven't checked too thoroughly) the original problem was in general about how to maintain the position.

    I actually had the same issue myself - don't remember right now the thread.

    Looking for a job opportunity.

    Beware of bugs in the above code; I have only proved it correct, not tried it.
    (Donald Knuth)

    Visit my blog

    PluralSight Learning Library
  • Re: Retain scroll position after postback

    07-06-2009, 4:17 AM
    • Member
      4 point Member
    • santhmon
    • Member since 03-23-2009, 9:20 AM
    • Posts 9

    Thanks 

  • Re: Retain scroll position after postback

    07-08-2009, 11:16 PM
    • Member
      116 point Member
    • chat2devesh
    • Member since 07-19-2007, 7:21 AM
    • Posts 24

     

    Use This One <@ % MaintainScrollPositionOnPostback="true" %>

  • Re: Retain scroll position after postback

    08-11-2009, 1:25 PM
    • Member
      2 point Member
    • essie
    • Member since 08-11-2009, 1:22 PM
    • Posts 1

    worked great, thanks! 

Page 2 of 2 (27 items) < Previous 1 2