设置始终聚焦于文本框(ASP.NET、Updatepanel)
嘿, 在我开始写问题之前,我会原谅我糟糕的英语,我希望你能理解我。
我在 ASP.NET Web 应用程序中有一个 AJAX 更新面板。在这个更新面板中有一个 动态搜索结果的文本框。当我开始在文本框中写入时,结果就像谷歌建议的那样。
现在,焦点必须始终位于文本框(输入字段)上,现在测量用户单击的位置。
目前,当用户开始键入时,ASP.NET 更新面板会在几秒钟后刷新。
感谢您的帮助:-)
Hey,
Before I start to write my problem, I will excuse for my bad English and I hope you can understand me.
I have in a ASP.NET Webapplication an AJAX Updatepanel. In this Updatepanel is a
Textbox for dynamic search results. When I start to write in the Textbox, the results comes like Google suggest.
Now, the focus must be always on the Textbox (inputn field), now metter whereto the User clicks.
Currently the ASP.NET updatepanel refreshed after a few seconds when the User starts to type.
Thanks for help :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当 updatepanel 完成更新 html dom 时会发生一个事件
尝试这个
there is an event when updatepanel finish updated html dom
try this
这很有趣,但这是一个可能的解决方案。这个想法是:如果用户离开文本框(onblur),则将他带回文本框(focusOnTxt 函数):
在 Page_Load 上:
That is pretty fun but here is a possible solution. The idea is: if user gets out of the textbox (onblur), then take him back to the textbox (focusOnTxt function):
And on Page_Load:
Page.Load 中的简单 SetFocus fe 应该可以工作:ScriptManager1.SetFocus (TextBox1.ClientID)更新:根据 这篇文章以下作品...
将此脚本添加到页面头部的脚本块中:
然后添加将 onfocus 事件添加到文本框:
在代码隐藏的 Page.Load 或 TextChanged-Event 处理程序中添加标准 SetFocus 调用:
A simple SetFocus f.e. in Page.Load should work:ScriptManager1.SetFocus (TextBox1.ClientID)UPDATE: according to this post following works...
Add this script into a script block in your page's head:
Then add the onfocus event to your Textbox:
In your codebehind's Page.Load or TextChanged-Event handler add the standard SetFocus call: