Click here to Skip to main content
13,457,972 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 20 Jul 2011

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

, 20 Jul 2011
Rate this:
Please Sign up or sign in to vote.
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.
<div onkeypress="return WebForm_FireDefaultButton(event, '<%= btnSubmit.ClientID %>')">
 <!-- put your form cntrols here -->
 <asp:Button ID="btnSubmit" runat="server" Text="Submit" />


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


About the Author

Bahram Ettehadieh
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.

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 5 Excellent tip! It solved my problem,... Pin
eyale7-Oct-11 7:59
membereyale7-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
memberAnkur\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
memberAnkur\m/20-Jul-11 7:20 
BugThis won't work Pin
Ankur\m/20-Jul-11 7:19
memberAnkur\m/20-Jul-11 7:19 
GeneralRe: This won't work Pin
Bahram Ettehadieh27-Jul-11 2:47
memberBahram Ettehadieh27-Jul-11 2:47 
GeneralRe: This won't work Pin
Ankur\m/27-Jul-11 3:23
memberAnkur\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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180323.1 | Last Updated 20 Jul 2011
Article Copyright 2011 by Bahram Ettehadieh
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid