ASP.NET AJAX UpdatePanel滚动问题
我会尽量简洁:
- 我有一个将
Autopostback
设置为true
的下拉列表, - 我有一个包含
Label
的 UpdatePanel。 - 当下拉列表选择更改时,我想更新标签。
问题:焦点在下拉列表上丢失,迫使用户单击下拉列表以将焦点重置回控件。
我的“解决方案”:在 DropDownList_SelectionChanged
事件中,将焦点设置回下拉列表:
dropdownlist1.focus()
虽然这在 IE 中效果很好,但 Firefox 和 Chrome 会更改滚动位置,以便定位分配焦点的控件位于浏览器窗口可见部分的底部。这通常是一个非常令人迷失方向的副作用。
如何避免这种情况,使其在 FF 中像在 IE 中一样工作?
I'll try and be concise:
- I have a dropdownlist with
Autopostback
set totrue
- I have an UpdatePanel that contains a
Label
. - When the downdownlist selection is changed, I want to update the label.
Problem: Focus is lost on the dropdownlist, forcing the user to click on the dropdownlist to reset focus back to the control.
My "solution": In the DropDownList_SelectionChanged
event, set focus back to the drop down list:
dropdownlist1.focus()
While this works great in IE, Firefox and Chrome change the scroll position such that the control which was assigned focus is positioned at the bottom on the visible portion of the browser window. This is often a very disorientating side effect.
How can this be avoided so it works in FF as it does in IE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以编程方式尝试使用以下 3 种方式之一进行 MaintainScrollPositionOnPostback
您可能还需要在 scriptmanager 声明之后添加此 javascript:
Try MaintainScrollPositionOnPostback in one of these 3 ways
You may also need to add this javascript after the scriptmanager declaration:
Velika - 抱歉耽搁了。
如果您使用母版页添加:
否则只需添加
Velika - Sorry for the delay.
If you are using a master page add :
Otherwise just add
有完全相同的问题并得到答案。希望这有帮助:
http://forums.asp.net/p/1622050/4164858.aspx#4164858
Had the exact same issue and got the answer. Hope this helps :
http://forums.asp.net/p/1622050/4164858.aspx#4164858
试试这个
try this one
这就是我一直在解决这个问题的方法。该示例需要 jquery,但如果需要,您可以重写。基本上只是延迟焦点脚本。
This is how I have been getting around this issue. The example requires jquery, but you could rewrite if needed. Basically just delays the focus script.