ASP.net Postback - Scroll to Specific Position(ASP.net 回传 - 滚动到特定位置)
问题描述
我有一个 ASP.net WebForms 页面,屏幕顶部有很多内容.它有一个链接按钮,可以回发到页面并显示页面的另一部分.当页面刷新时,我想设置焦点并向下滚动到页面的这一部分.
I have an ASP.net WebForms page that has a lot of content on the top of the screen. It has a link button that will post back to the page and show another section of the page. When the page refreshes, I would like to set focus and scroll down to this section of the page.
我尝试过
txtField.Focus()
在我后面的代码中,它会设置焦点并尝试在那里滚动,但随后会直接滚动到顶部.焦点仍然在我的文本框上,但屏幕的位置在最顶部.链接位于导致回发的屏幕顶部.我想滚动到屏幕的最底部.它会简单地执行此操作,然后直接滚动到顶部.
in my code behind and it will set focus and try to scroll there, but then scrolls right back to the top. The focus is still on my text box but the position of the screen is at the very top. The Link is at the top of the screen which is causing the postback. I want to scroll to the very bottom of the screen. It does this briefly and then scrolls right back to the top.
我试过设置
Page.MaintainScrollPositionOnPostback = false;
但这似乎也无济于事.
有什么方法可以强制它转到特定位置吗?当我使用按钮或链接按钮回发时,是否可以向 URL 添加锚标记?
Is there some way I can force it to go to a specific position? Is it possible to add an anchor tag to the URL when I postback using a button or link button?
推荐答案
Page.MaintainScrollPositionOnPostBack = true;
应该会带你回到屏幕上的相同位置,但你可以使用 AJAX,或者你可以使用 SetFocus()
在回发后专注于特定控件:
Page.MaintainScrollPositionOnPostBack = true;
should take you back to the same position on the screen, but you could use AJAX, or you could use SetFocus()
to focus on a specific control after the postback:
http://msdn.microsoft.com/en-us/library/ms178232.aspx
这篇关于ASP.net 回传 - 滚动到特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.net 回传 - 滚动到特定位置
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01