How to use Enter Key as the default to submit questions in ASP.NET2.0
This article introduces the relevant knowledge of "how to use Enter Key as the default to submit questions in ASP.NET2.0". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
One of the most annoying things in web development is dealing with "Enter key" for forms, and "Enter key" has become a preference for users to submit forms. Although we provide users with a submit button, the simplest and most direct way is to enter text and then enter to complete the submission.
ASP.NET 2.0 provides a good solution to this. You just need to specify the "defaultbutton" property to the ID of the button control that you want to raise the event.
"defaultbutton" can be specified at both the form level and the panel level (tags). When defaultbutton is specified in both the form and the panel, if "Enter key" is triggered in the panel, execute the
The following example code has a form and four panels, with buttons in both the report and the panel. Attention: the event of which buttons will be triggered after you enter in the text box
/ The corresponding, sample events for the button clicks areprotected void Button1_Click (object sender, EventArgs e) {Response.Write (Button1.Text);} protected void Button2_Click (object sender, EventArgs e) {Response.Write (Button2.Text);} protected void Button3_Click (object sender, EventArgs e) {Response.Write (Button3.Text);} protected void Button4_Click (object sender, EventArgs e) {Response.Write (Button4.Text);} protected void btn1_Click (object sender, EventArgs e) {Response.Write (btn1.Text) } protected void Button5_Click (object sender, EventArgs e) {Response.Write (Button5.Text);} "how to use Enter Key as the default to submit questions in ASP.NET2.0" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!