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


Leave a Comment Subscribe to RSS Feed Subscribe by Email
  1. Kamil Kaproń
    March 30th, 2009

    Comment Arrow

    Great tip!

  2. Michael
    July 29th, 2009

    Comment Arrow

    Brilliant! I’ve been looking everywhere for something like this, though now I’m not sure I want it to happen on every request, but so far it works great.

  3. Comment Arrow

    Thanks buddy.
    Its a great tip which i was searching a long time and left as i didn get any idea.
    good work.
    God bless

  4. Comment Arrow

    Thanks mate. It was wonderful

Trackbacks

  1. Drew Miller » Ajax Scroll To Top of Page

Leave a Comment