保持滚动位置在页面上有很多更新面板? [英] Maintain scroll position having many update panels in th page?

查看:88
本文介绍了保持滚动位置在页面上有很多更新面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当页面中有很多更新面板时,如何保持滚动条的位置?

这些更新面板在内部具有每秒钟更新一次的标签.
因此,页面滚动条每隔一秒钟就会将其位置重置为顶部.

我在@page指令中添加了MaintainScrollPositionOnPostback ="true",但这仅在页面回发时才有用.

How to maintain scroll bar position, when i am having many update panels in a page?

These update panels internally have labels which update for every sec.
So, for every second the page scrollbar is resetting its position to top.

I have added, MaintainScrollPositionOnPostback ="true" in the @page directive but this is helpful only when the page is posted back. How can i maintain the scroll position when the page is asynchronously posted back.

推荐答案

您需要使用:Java中的PageRequestManager 类DOM元素.

使用该类的BeginRequest EndRequest 事件来跟踪更新面板的滚动位置.
BeginRequest将跟踪滚动在更新之前的位置,EndRequest将滚动位置恢复到较早的位置.

Javascript PseudoCode将为:
You need to use: PageRequestManager class DOM element in Javascript.

Use BeginRequest and EndRequest events of the class to track the scroll position of the updatepanels.
BeginRequest would keep track of where the scroll was before update and EndRequest would restore the scroll position back to earlier one.

Javascript PseudoCode would be:
//Register Begin Request and End Request 
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

//Get The Div Scroll Position
function BeginRequestHandler(sender, args) 
{
   var m = document.getElementById('divGrid');
   scrollTop=m.scrollTop;
}

//Set The Div Scroll Position
function EndRequestHandler(sender, args)
{
   var m = document.getElementById('divGrid');
   m.scrollTop = scrollTop;
} 


PageRequestManager类上阅读 [


Read on PageRequestManager Class[^]


这篇关于保持滚动位置在页面上有很多更新面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆