Monday, May 2, 2011

Default button for ENTER key using C#

Sometimes you may want a button's on click event to occur on the press of the ENTER key.
In such cases there are a number of ways to do it.
I'll show you 2 of these many ways.


1. In your FORM element in your aspx page add an attribute

<form id="form1" runat="server" defaultbutton="Button1">
<div>
<asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
</div>
<form>
2. On page_load method add:

Form.DefaultButton = Button_Name.UniqueID;


0 comments:

Post a Comment

 

2011 ·Code-Studio by yrus.