C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Cause button click on Enter


Posted Date: 13 Mar 2004    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: SivaMember Level: Gold    
Rating: 1 out of 5Points: 4




Pressing the Enter key on an ASP.NET form doesn't necessarily cause a form submission. To force a particular button on the page to fire and cause a postback on Enter, simply add one line of code:

Page.RegisterHiddenField("__EVENTTARGET", "BUTTON_NAME")

Change BUTTON_NAME to the ID of the button to which you want to default. This trick is limited by certain controls in HTML, such as a multiline textbox in which the default action is to create a new line.

Siva



Responses

Author: Randy Shoemake    22 Jun 2004Member Level: Bronze   Points : 0
Perfect, Simple, and Effective.


Author: Derrick Robinson    23 Dec 2004Member Level: Bronze   Points : 0
Siva,

I cannot get this code to work. I placed it in the page load event. Is that not the right place.

Page.RegisterHiddenField("__EVENTTARGET", "btnMyButton")

I also imported the System.Web.UI namespace


Author: Anil Somanathan    03 Aug 2005Member Level: Bronze   Points : 0
Its the right place to put the code. Put it with a little modification
Page.RegisterHiddenField( "__EVENTTARGET", yourButton.ClientID);


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Adding common functionality with user controls
Previous Resource: Adding Row Numbers
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use