Click here to Skip to main content
15,867,308 members
Articles / Web Development / ASP.NET
Tip/Trick

How to make a button the default button on enter on an ASP.NET form

Rate me:
Please Sign up or sign in to vote.
3.00/5 (3 votes)
20 Jul 2011CPOL 34.3K   8   6
By putting your intended content in a division as bellow, the button you set as default button will be hit when you hit enter button on any element which is in the division.
XML
<div onkeypress="return WebForm_FireDefaultButton(event, '<%= btnSubmit.ClientID %>')">
 <!-- put your form cntrols here -->
 
 <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</div>

License

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


Written By
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
I hold a BS degree in software engineering and am a Microsoft Certified Solution Developer(MCSD).
I have more than 8 years of experience in .NET developement, mostly web develop using C# and ASP.NET.

Comments and Discussions

 
GeneralReason for my vote of 5 Excellent tip! It solved my problem,... Pin
eyale7-Oct-11 7:59
eyale7-Oct-11 7:59 
GeneralReason for my vote of 1 For the reasons mentioned in my mess... Pin
Ankur\m/27-Jul-11 1:37
professionalAnkur\m/27-Jul-11 1:37 
GeneralYour tip isn't correct, IMHO. I have added a detailed messag... Pin
Ankur\m/20-Jul-11 7:20
professionalAnkur\m/20-Jul-11 7:20 
BugThis won't work Pin
Ankur\m/20-Jul-11 7:19
professionalAnkur\m/20-Jul-11 7:19 
GeneralRe: This won't work Pin
Bahram Ettehadieh27-Jul-11 2:47
Bahram Ettehadieh27-Jul-11 2:47 
GeneralRe: This won't work Pin
Ankur\m/27-Jul-11 3:23
professionalAnkur\m/27-Jul-11 3:23 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.