views:

308

answers:

2

Hello

I have an asp.net page that is using an UpdatePanel control. When you're on the page and you click the continue button, the page does a partial refresh and you're left in the same scroll position you were before the refresh. How do I ensure that on partial refreshes with the UpdatePanel control that you return to the top of the page.

thanks

+3  A: 

There is a javascript call to move the scroll to the top of the page:

window.scrollTo(0,0);

You can wire an event handler to the completion of your AJAX call and add that javascript to your event handler.

Matt Hamsmith
For ASP.Net, wiring the end request event handler is like this:<script type="text/javascript">Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);function EndRequestHandler(sender, args) { window.scrollTo(0,0);}</script>
Matt Hamsmith
+1  A: 

Here is how you do it using jquery and the updatepanel

<script type="text/javascript">
   var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();

   pageRequestManager.add_endRequest(function() {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
    });
</script>
Dug