Search code examples
asp.netascx

How do I associate the Enter key with a button on an aspx page?


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

I am using a master page with a button already on it, so now when I press the enter key, the event handler for that button fires.


Solution

  • DefaultButton also works in panels, so you can set a default button in each panel and have the Enter key click the button in whichever panel currently has focus.