多视图和多视图在回发时维护滚动位置
我有一个带有 MultiView 控件的页面,并且某些视图的长度足以滚动。由于评论中的许多控件需要回发才能正常工作,因此在页面上启用了MaintainScrollPositionOnPostBack。
当用户从一种视图转换到另一种视图时,我遇到问题。如果它们位于长视图的底部,并转换到另一个长视图,则新视图会加载并一直滚动到底部。当用户进入多视图中的新视图时,我需要跳转到页面顶部。
我尝试使用 OnActiveViewChanged 事件来: - 调用 RegisterStartupScript 将 window.location.hash 设置为我放置在页面顶部的锚点。 - 调用RegisterStartupScript调用window.scrollTo(0,0) - 暂时将MaintainScrollPositionOnPostBack 设置为 false
问题是,这些似乎都不会影响实际的转换回发,它们会在下一个回发时生效,这实际上会导致更大的问题。
有人有一种行之有效的方法,可以让 MultiView 页面仅在转换到新视图的回发时跳转到页面顶部吗?
I have a page with a MultiView control, and some of the views are long enough to scroll. Since may of the controls in the reviews require postback to function properly, MaintainScrollPositionOnPostBack is enabled on the page.
I have a problem when the user transitions from one view to another. If they were at the bottom of a long view, and transition to another long view, the new view loads and is scrolled all the way to the bottom. I need to jump to the top of the page when the user goes to a new view within the MultiView.
I've tried using the OnActiveViewChanged event to:
- call RegisterStartupScript to set window.location.hash to an anchor that I placed at the top of the page.
- call RegisterStartupScript to call window.scrollTo(0,0)
- set MaintainScrollPositionOnPostBack to false temporarily
The problem is that none of these seem to affect the actual transition postback, they take effect on the next postback, which actually causes a bigger issue.
Anybody have a proven method to have a MultiView page jump to top of page only on postbacks that transition to a new view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这与我今天在多视图中遇到的问题完全相同。我找到了你的问题并开始寻找答案。看来我们找到了同一篇文章!
(文章代码为C#)
This is exactly the same problem I've been having today with a multiview.. I found your question and went looking for answers. Seems we found the same article!
(Article code in C#)
最后找到了答案/解决方法: 4Guys
您必须通过操纵 ASP.Net 用于跟踪滚动位置的隐藏字段来欺骗 ASP.Net 来为您完成此操作。
Found an answer/workaround, finally: 4Guys
You have to trick ASP.Net into doing it for you by manipulating the hidden fields it uses for tracking the scroll position.