Resetting scroll position after completion of the partial update

When you use the UpdatePanel to implement partial updates,the scroll position will be maintained between the asynchronous post-backs.However,you may need to reset the scroll position after the partial update completed ( after receiving the response).

To do that you can handle the PageRequestManager endrequest event  and use window.scrollTo JavaScript method.

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function() { window.scrollTo(0, 0); });
        </script>

Note: make sure to place the scrip inside the Form element , otherwise you will get exceptions like Sys is not defined.

Published Friday, January 02, 2009 12:56 AM by anas
Filed under: ,

Comments

# re: Resetting scroll position after partial update Completed.

Monday, January 05, 2009 1:49 AM by Nemesis116

Good tip!

# re: Resetting scroll position after partial update Completed.

Monday, February 02, 2009 2:35 PM by Cire1507

This code snippet is something which we can use in our organization. Well done.

Leave a Comment

(required) 
(required) 
(optional)
(required)