Maintain scroller position on Div after page postback (ASP.NET)

后端 未结 6 1066
执念已碎
执念已碎 2021-01-05 05:30

I have a div as such:

I contains a few hundred records and allows me to select an i

6条回答
  •  青春惊慌失措
    2021-01-05 05:50

    Disclaimer - not my code, but I've seen this used before:

    window.onload = function(){
        var strCook = document.cookie;
        if(strCook.indexOf("!~")!=0){
          var intS = strCook.indexOf("!~");
          var intE = strCook.indexOf("~!");
          var strPos = strCook.substring(intS+2,intE);
    
          document.getElementById("divTest").scrollTop = strPos;
          document.getElementById("divTest").scrollTop = strPos;
        }
      }
      function SetDivPosition(){
        var intY = document.getElementById("divTest").scrollTop;
    
        document.cookie = "yPos=!~" + intY + "~!";
      }
    

    The idea is to store the position of the scrollbar in a cookie. Another (better?) option would be to store it in a hidden field (or fields). Hope that gets you going...

提交回复
热议问题