问题
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:
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);
}
来源:https://stackoverflow.com/questions/2874981/scroll-to-top-of-page-after-asp-net-ajax-async-postback-without-jquery