Handling the Enter Key is one of the challenges faced by Web Developers and one has to resort to different means like writing Javascript to handle the enter key event. With ASP.NET 2.0, there is a DefaultButton property for Forms, Panels etc., which can help you in handling the enter key in an efficient way. This scenario explains a basic Enter Key Functionality.
The Code below shows the ASPX Design and the Controls Declaration
Note the Default Button (defaultButton="Button3") property of the form tag. This determines, which Button Click to fire when the Enter Key is pressed.
The Code below shows the C# Code behind. Note that the significance of this example is in the above code snippet (Design and Control Declaration) and the code behind is just to have Button Click Events to do a Response.Write of respective Button Name.
protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Button 1 is Clicked !"; } protected void Button4_Click(object sender, EventArgs e) { Label1.Text = "Button 4 is Clicked !"; } protected void Button3_Click(object sender, EventArgs e) { Label1.Text = "Button 3 is Clicked !"; } protected void Button2_Click(object sender, EventArgs e) { Label1.Text = "Button 2 is Clicked !"; }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|