65.9K
CodeProject is changing. Read more.
Home

Calling Control on Pressing Enter

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.81/5 (7 votes)

Jul 12, 2006

viewsIcon

18733

Calling Control on Pressing Enter

Introduction

If you had browsed through many search engines(obviously one cant avoid it in course of each day), once you give the search word and press "Enter Key", the page automatically searches and displays the results. Now when it comes to implementation of the same in our development what need to be done?
 
Suppose you have a textbox and when the user enters some text in the textbox and presses enter , the page have to fire the Event for "btnEnter" in the page. What need to be done?
 
Just a line will resolve the issue.
 
On the Page_Load Event of the Page write the following line
           
            Page.RegisterHiddenField("__EVENTTARGET","btnEnter");
 
Replace "btnEnter" with with button name on your screen.
 
Once this is done, on enter in the textbox the event is fired. There are few more round about methods for which we can attach a javascript function to textbox and perform the operation.
 
Hope this little piece of code is useful for all
 
Regards
Umanath