Click here to Skip to main content
Click here to Skip to main content

Calling Control on Pressing Enter

By , 11 Jul 2006
 

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Umanath Selvan
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionWouldn't setting DefaultButton be better?memberMike Ellison12 Jul '06 - 6:14 
Hi there. You can accomplish what you describe by using the DefaultButton property on the form or a panel-
 
<form runat="server" DefaultButton="myButton">
  ...
  
  <asp:Button id="myButton" runat="server" ... />
</form>
 
<asp:Panel runat="server" DefaultButton="myButton2">
   ...
  <asp:Button id="myButton2" runat="server" ... />
</asp:Panel>     
How does your method compare? Does it give a benefit that DefaultButton doesn't?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 12 Jul 2006
Article Copyright 2006 by Umanath Selvan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid