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.
+1
A:
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);
}
Daniel Dyson
2010-05-20 15:08:46
Yes, but as I said, ASP.Net scrolls back down to where the click occurred.
Payton Byrd
2010-05-20 15:10:25
window.setTimeout("window.scrollTo(0, 0)", 3000);
Daniel Dyson
2010-05-20 15:13:19
Setting the timeout worked! Yay!
Payton Byrd
2010-05-20 15:16:24
Yes, but it is a workaround solution. It smells a bit. Could you try the other idea I had as well?
Daniel Dyson
2010-05-20 15:18:55