CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Moveor Scroll Page to Top After Asynchronous Postback in UpdatePanel in ASP.Net AJAX
Submitted By Satheesh Babu B
On 7/7/2009 7:03:27 AM
Tags: ASP.Net AJAX,CodeDigest  

Move or Scroll Page to Top After Asynchronous Postback in UpdatePanel in ASP.Net AJAX

 

Sometimes, we may require moving or scrolling the page to top after asynchronous postback caused in a lengthier page. We can do this with the help of PageRequestManager's end request event.

To move the focus to top of the window, we can use  the window.scrollTo() event in the PageRequestManager's end request event by setting the co-ordinates to (0,0) which represents top (0,0) pixel location.

 

The below code can be used to do that.

 

<script type="text/javascript">

    function pageLoad() {

        var manager = Sys.WebForms.PageRequestManager.getInstance();

        manager.add_endRequest(endRequest);

    }

    function endRequest(sender, args) {

        window.scrollTo(0, 0);

    }

 

</script>

 

After any asyncronous postback on the page, the above endRequest event will run and will move your page to top.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..