问题描述
我有一个 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 回传 - 滚动到特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!