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

只愿长相守 提交于 2019-12-10 19:51:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!