Submit form when Enter is pressed

22,718

Solution 1

You set the forms default button:

<form id="Form1"
    defaultbutton="SubmitButton"
    runat="server">

Solution 2

Make it the default button of the form or panel.

Either one has a DefaultButton property that you can set to the wanted button.

Share:
22,718
Jishnu A P
Author by

Jishnu A P

Aspiring polymath

Updated on August 12, 2022

Comments

  • Jishnu A P
    Jishnu A P almost 2 years

    I have an aspx page with many buttons and i have a search button whose event i want to be triggered when user press enter. How can i do this?

  • Jishnu A P
    Jishnu A P over 13 years
    But the form that i use is in the master page!
  • m.edmondson
    m.edmondson over 13 years
    Try this Page.Form.DefaultButton = "Button1"
  • a2f0
    a2f0 almost 10 years
    I'd recommend looking into this as well, "this.Form.DefaultButton = this.ibRecalc.UniqueID;" stackoverflow.com/questions/3614797/…
  • Andrew Grinder
    Andrew Grinder over 9 years
    @dps comment works best when you have a master page that has its own form tags. You cannot put another form within a form.