65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (3 votes)

Jul 20, 2011

CPOL
viewsIcon

35824

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" />
</div>