如何在Asp.net中为文本框应用键盘事件 [英] how to apply keyboard events in Asp.net for textbox

查看:87
本文介绍了如何在Asp.net中为文本框应用键盘事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在asp.net c#中应用键盘事件....
例如

如果我在文本框中输入员工ID
那么应从db中获取其名称,并在下一个文本框中显示该名称.

我可以这样做吗?

how can i apply keyboard event in asp.net c#....
for example

if i entered in textbox employee id
then its name should be fetched from db and displayed in next textbox.

can i do that???

推荐答案

请参阅我对问题的评论.显然,是我解释的原因,该事件是System.Web.UI.WebControls.TextBox.TextChanged: http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.textbox.textchanged.aspx [ http://api.jquery.com/change/ [ http://en.wikipedia.org/wiki/JQuery [ http://jquery.com/ [ ^ ],
http://docs.jquery.com/How_jQuery_Works [
Please see my comments to the question. Apparently, be the reasons I explain, the event is System.Web.UI.WebControls.TextBox.TextChanged: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx[^].

However, this is a bad idea: too many postbacks, bad for performance. It would be better to write JavaScript to do it all on the client side only. I would recommend using jQuery, a very robust and easy-to-use JavaScript library. This is the analog of this event, please see the code sample after the words "The event handler can be bound to the text input and the select box":
http://api.jquery.com/change/[^].

See also:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^],
http://docs.jquery.com/How_jQuery_Works[^].

—SA


这篇关于如何在Asp.net中为文本框应用键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆