Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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???
Posted
Comments
Sergey Alexandrovich Kryukov 1-Nov-12 2:41am    
What exactly do you mean by "applying an event"? Handle event? Then what do you mean by "entered"? On each key press or what? After all, read the section Events of the TextBox control you use, in MDSN help page. What's the problem?
--SA
sumit kausalye 1-Nov-12 3:11am    
sir actually i want
when i enter employee id in a text then it automatically fetch the employee id from database and the name of employee should be displayed in next textbox without button click so which keyboard event should i used and how in asp.net c#???
Sergey Alexandrovich Kryukov 1-Nov-12 3:47am    
Apparently, "without button" means on each key press, so the event is... TextChanged.
--SA
sumit kausalye 1-Nov-12 3:56am    
on keyup sir i mean when i finish enter employee id and when i clicked on name textbox that time it should show me the name from the database

1 solution

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
 
Share this answer
 
Comments
adriancs 1-Nov-12 5:05am    
textbox can be wrapped (the output of the employee name) inside an updatepanel. This can prevent a full postback. Slightly better performance.
Sergey Alexandrovich Kryukov 1-Nov-12 11:13am    
I did not try such thing, but if you look at the question, you will see that the whole problem belongs to client side and hence its totally JavaScript; and the scripting is way too simple.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900