多视图和多视图在回发时维护滚动位置

发布于 2024-10-14 16:03:33 字数 531 浏览 10 评论 0原文

我有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒人说梦 2024-10-21 16:03:33

这与我今天在多视图中遇到的问题完全相同。我找到了你的问题并开始寻找答案。看来我们找到了同一篇文章!

(文章代码为C#)

 private void ResetScrollPosition()
  {
      if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "CreateResetScrollPosition"))
      {
          System.Text.StringBuilder script = new System.Text.StringBuilder();
          script.Append("function ResetScrollPosition() {");
          script.Append("  var scrollX = document.getElementById(\'__SCROLLPOSITIONX\');");
          script.Append("  var scrollY = document.getElementById(\'__SCROLLPOSITIONY\');");
          script.Append("  if (scrollX && scrollY) {");
          script.Append("    scrollX.value = 0;");
          script.Append("    scrollY.value = 0;");
          script.Append("  }");
          script.Append("}");

          //Create the ResetScrollPosition() function
          ClientScript.RegisterClientScriptBlock(this.GetType(), "CreateResetScrollPosition",
             script.ToString(), true);
          //Add the call to the ResetScrollPosition() function
          ClientScript.RegisterStartupScript(this.GetType(), "CallResetScrollPosition", "ResetScrollPosition();", true);
      }
  }

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#)

 private void ResetScrollPosition()
  {
      if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "CreateResetScrollPosition"))
      {
          System.Text.StringBuilder script = new System.Text.StringBuilder();
          script.Append("function ResetScrollPosition() {");
          script.Append("  var scrollX = document.getElementById(\'__SCROLLPOSITIONX\');");
          script.Append("  var scrollY = document.getElementById(\'__SCROLLPOSITIONY\');");
          script.Append("  if (scrollX && scrollY) {");
          script.Append("    scrollX.value = 0;");
          script.Append("    scrollY.value = 0;");
          script.Append("  }");
          script.Append("}");

          //Create the ResetScrollPosition() function
          ClientScript.RegisterClientScriptBlock(this.GetType(), "CreateResetScrollPosition",
             script.ToString(), true);
          //Add the call to the ResetScrollPosition() function
          ClientScript.RegisterStartupScript(this.GetType(), "CallResetScrollPosition", "ResetScrollPosition();", true);
      }
  }
美人如玉 2024-10-21 16:03:33

最后找到了答案/解决方法: 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文