Scroll to top of page after ASP.Net Ajax Async-Postback without JQuery

asp.netasp.net-ajax

I need to scroll to the top of the page after an Async Postback in an update panel. I've tried a couple of methods, and while they all scroll to the top of the page, they all get "overriden" by ASP.Net Ajax which returns the page to where it was when the postback occurs. I have already set MaintainScrollPositionOnPostBack="false" in the Page directive.

Best Answer

Have you tried window.scrollTo(0, 0); ?

If you have, perhaps combine in with setTimeout

window.setTimeout("window.scrollTo(0, 0)", 3000);

Although I expect this might produce some ugly jumping around.

An alternative would be to hook into the EndRequest event handler

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
    window.scrollTo(0, 0);
}