asp.net 2.0-enter key-default Submit Button

Source: Internet
Author: User
asp.net

One of the most annoying things about web development is that it handles "enter key" for a form, and "Enter key" has become a user's preference for submitting a form. Although we provide the user with the Submit button, the simplest and most straightforward way is still to enter the text and return to complete the submission

ASP.net 2.0 provides a good solution for this. You only need to assign the "DefaultButton" attribute to the ID of the button control that you want to raise the event.

You can specify "DefaultButton" at both the form level and the panel level (<asp:panel> tag). When DefaultButton is specified in the form and panel, if Enter key is triggered in the panel, the

The following instance code has a form and 4 panels, with buttons in both the declarations and the Panel. Everyone note: Which button events are triggered when you enter a carriage return in a text box

<form id= "Form1" runat= "Server" defaultbutton= "BTN1" >

<div>
<asp:textbox id= "TXT" runat= "server" ></asp:TextBox>
<asp:button id= "Button5" runat= "Server" text= "Cancel"/>
<asp:button id= "BTN1" runat= "Server" text= "Submit"/>
<asp:panel id= "PNL1" runat= "Server" defaultbutton= "Button1" >
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>
<asp:textbox id= "TextBox2" runat= "Server" ></asp:TextBox>
<asp:button id= "Button1" runat= "Server" text= "Button1"/>
</asp:Panel>
<asp:panel id= "Panel1" runat= "Server" defaultbutton= "Button2" >
<asp:textbox id= "TextBox3" runat= "Server" ></asp:TextBox>
<asp:textbox id= "TextBox4" runat= "Server" ></asp:TextBox>
<asp:button id= "Button2" runat= "Server" text= "Button2"/>
</asp:Panel>
<asp:panel id= "Panel2" runat= "Server" defaultbutton= "Button3" >
<asp:textbox id= "TEXTBOX5" runat= "Server" ></asp:TextBox>
<asp:textbox id= "TextBox6" runat= "Server" ></asp:TextBox>
<asp:button id= "Button3" runat= "Server" text= "Button3"/>
</asp:Panel>
<asp:panel id= "Panel3" runat= "Server" defaultbutton= "Button4" >
<asp:textbox id= "TextBox7" runat= "Server" ></asp:TextBox>
<asp:textbox id= "TextBox8" runat= "Server" ></asp:TextBox>
<asp:button id= "Button4" runat= "Server" text= "Button4"/>
</asp:Panel>
</div>
</form>

The corresponding, sample events for the button clicks are
protected 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);
}

Original: Http://forums.asp.net/thread/1270048.aspx


Original: Http://forums.asp.net/thread/1270048.aspx
Code download

Really do not know "Entry key" should how to translate, please advise.
Thank you



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.