How To Scroll To Top Of Page On An AJAX Postback [ASP.NET]

Scrolling to top of the page on an Ajax request in ASP.NET page is quite tricky. The regular inline anchor techniques does not work. We need to handle the endRequest event and scroll the window to 0,0 coordinates(top of the page).

Here is the sample code that can be pasted on your aspx page to scroll an ASP.NET page to top on every Ajax postback operation.

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestEventHandler);
function EndRequestEventHandler(sender, args)
{
    scrollTo(0,0)
}
</script>
Bookmark and Share
Did you enjoy this article? If so, then subscribe to our RSS Feed or free daily newsletter.

2 Responses to “How To Scroll To Top Of Page On An AJAX Postback [ASP.NET]”

  1. Drew Miller » Ajax Scroll To Top of Page

    [...] down on the page the AJAX postback wouldn’t return the focus to the top of the next page. This blog post offered a quick solution that solved my problem quite nicely. <script type=”text/javascript” [...]

  2. Kamil Kaproń

    Great tip!

Leave a Reply