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.
|