列表框在自动回发时滚动到顶部
为什么当自动回发打开时,asp.net 列表框在选择某个项目时总是滚动到顶部?我怎样才能防止这种情况发生?
Why does asp.net listbox always scroll to top upon selecting an item when autopostback is on? How can I prevent this from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你有几个选择。您可以在页面指令中将MaintainScrollPositionOnPostBack 设置为true,也可以将列表框放在更新面板中并使用AJAX 来维护滚动位置。
页面指令选项:
更新面板选项:
You have a couple of options. You can either set MaintainScrollPositionOnPostBack to true in the page directive, or you can put the listbox in an update panel and use AJAX to maintain scroll position.
Page directive option:
Update panel option:
我在 javascript 中添加了以下 jquery 来解决该问题。我不记得在哪里找到了解决方案,但它就在这里。只需添加目标控件的位置 - $get('YourDiv_YourPanel')。
I added the following jquery in javascript to fix the issue. I cannot remember where I found the solution but here it is. Just add the location of your target control - $get('YourDiv_YourPanel').
我遇到了同样的问题,我找到了一种使用更新面板来解决此问题的方法。我相信这是由于列表框在回发时更新,因此更新面板可以帮助我们确保它不会更新。确保列表框位于条件更新面板内,并将子项作为触发器设置为“false”:
现在,将列表框选择更改时需要更改的内容放入其自己的更新面板内。这样列表框就不会刷新。
I had the same issue, and I figured out a way to do it with update panels. I believe it's due to the listbox being updated on postback, so update panels can help us make sure it doesn't update. Make sure the listbox is inside a conditional update panel with children as triggers set to 'false':
Now put whatever needs to be changed when the list box selection changes inside an update panel of its own. That way the listbox doesn't get refreshed.
您需要此页面指令:
You need this page directive: