How to bind Enter key using button on aspx page?

I have an asp.net ascx control file and I set the control on an aspx page. There is a button on the aspx page in which, when I press the enter key on the keyboard, I want it to fire an event handler for the button. Is there any way to fix this?

I use the main page with the button already on it, so now when I press the enter key, the event handler for this button starts.

+5
source share
5 answers

DefaultButton also works in panels, so you can set a default button on each panel and press Enter to click on the button, depending on which panel is currently in focus.

+7
source

This is subtle in IE. You will need to add a text field to your control, set the display to no and visibility to hidden, which should not affect the appearance of your control, since this text field will be hidden, the input should work correctly, this is an IE problem

Edit: ignore this if you are using .NET 2.0 which introduced defaultButton

+2
source

:

<form id="form1" runat="server" defaultbutton="myButton">
+1

Page.Form.DefaultButton - msdn link here

+1
source

Just a small note: You cannot use the defaultButton attribute if your button is LinkButton, it does not work for this, taken from here: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols. htmlform.defaultbutton.aspx

0
source

All Articles