How to handle the form submission by pressing enter in Asp.net

Source: Internet
Author: User

During the development process, I was always confused by the problem: if there are several logical forms on the page, it would be okay if you click the corresponding buttons. However, if you press enter directly after entering the form content, the form will be submitted but will not be processed.

In the past, we had to write a JS script. Today we finally found a simple method.

We only need to set the defaultbutton attribute on the form parent container and set its value to the button we want the user to click. In this way, when the user presses the carriage return, it will precisely submit the desired form.

Example:

<Asp: Panel id = "pnllogin" runat = "server" cssclass = "right_login" defaultbutton = "btnlogon">
<Table>
<Tr>
<TD> <p> User name: </P> </TD>
<TD> <asp: textbox id = "tbxusername" runat = "server" cssclass = "login"> </ASP: textbox> </TD>
</Tr>
<Tr>
<TD> <p> password </P> </TD>
<TD>
<Asp: textbox id = "tbxpassword" runat = "server" cssclass = "login" textmode = "password"> </ASP: textbox>
<Asp: button id = "btnlogon" runat = "server" cssclass = "searchsubmit" text = "Logon" onclick = "btnlogon_click"/>
</TD>
</Tr>
</Table>
</ASP: Panel>

After this setting, you can press enter and click "Log on" to achieve the same effect. It is very user-friendly and convenient, isn't it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.