简体   繁体   中英

Asp.net - Keep Scroll Position after page refresh or reload

I'm new to javascript and asp.net. I'm using linkbuttons in my page and when I click the buttons my page reloads and page scroll to the top.

I tried this script and it doesn't work.

<script type="text/javascript">
        var xPos, yPos;
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(EndRequestHandler);

        function BeginRequestHandler(sender, args) {
            xPos = document.body.scrollLeft;
            yPos = document.body.scrollTop;
        }

        function EndRequestHandler(sender, args) {
            document.body.scrollLeft = xPos;
            document.body.scrollTop = yPos;
        }
    </script>

只需在页面指令中添加MaintainScrollPositionOnPostback =“ true”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM