Javascript – How to keep whole page scroll position after asynchronous postback

asp.netasynchronousasynchronous-postbackjavascript

i am using asp.net 4.0 iis 7.5 microsoft visual studio 2010

what i want is keep whole page (browser) scroll position (not a div or panel) when asynchronous postback happened (update panel)

how can i do this

actually i had a function which can keep div scroll bar position after postback like this

       <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 = document.getElementById('Main').scrollLeft;
            yPos = document.getElementById('Main').scrollTop;
        }
        function EndRequestHandler(sender, args) {
            document.getElementById('Main').scrollLeft = xPos;
            document.getElementById('Main').scrollTop = yPos;
        }
    </script>

bu i could not find browser scroll bar id to get its values to get with document.getElementById

thanks for answers

Best Answer

asp.net has @page directive property called MaintainScrollPositionOnPostBack

hope this will help