Maintain scroll position in listboxes in updatepanels, NOT the page

后端 未结 5 1793
臣服心动
臣服心动 2020-12-05 21:38

I have a listbox inside an update panel. When I scroll down and select an item, it scrolls back to the top of the listbox. I heard that the dom does not keep track of the

5条回答
  •  自闭症患者
    2020-12-05 22:14

        var xPos, yPos;
        var prm = Sys.WebForms.PageRequestManager.getInstance();
    
        function BeginRequestHandler(sender, args) {
            if (($get('Panel1')) != null) {
                xPos = $get('Panel1').scrollLeft;
                yPos = $get('Panel1').scrollTop;
            }
        }
    
        function EndRequestHandler(sender, args) {
            if (($get('Panel1')) != null) {
                $get('Panel1').scrollLeft = xPos;
                $get('Panel1').scrollTop = yPos;
            }
        }
        prm.add_beginRequest(BeginRequestHandler);
        prm.add_endRequest(EndRequestHandler);
    
        //Note: "Panel1" Panel or div u want to maintain scroll position
        //Note: This Java Script should be added after Scriptmanager*****
    

    //Maintain Scroll Position for Panel/Div with out Update panel

        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('Panel1').scrollTop = strPos;
            }
        }
        function SetDivPosition() {
            var intY = document.getElementById('Panel1').scrollTop;
            document.title = intY;
            document.cookie = "yPos=!~" + intY + "~!";
        }
    
    
       //Note: "Panel1" Panel id or div id for which u want to maintain scroll position
    

提交回复
热议问题