Take advantage of DefaultButton property in ASP.NET 2.0
If you are new to ASP.NET 2.0, then this would be good news to you! If you have more than one button on a form and if you wanted to keep a specific button as default one, then the DefaultButton property helps you to specify any button on a form as the default button when the form loads.
(For a new commer to the web development, the default button is the button which will post back to the server if you press the ENTER key)
For example, if you wanted to specify SubmitButton as a default button, then the syntax would be as shown below.
<form id="Form1"
defaultbutton="SubmitButton"
defaultfocus="TextBox1"
runat="server">
Complete example:
<%@ page language="C#" %>
<html>
<head>
<script runat="Server">
void Page_Load(object sender, System.EventArgs e)
{
Label1.Text = "The DefaultButton property is set to "
+ Form1.DefaultButton.ToString() + "<br/>";
Label2.Text = "The DefaultFocus property is set to "
+ Form1.DefaultFocus.ToString();
}
void CancelButton_Click(object sender, EventArgs e)
{
Response.Write("Cancle is clicked");
}
</script>
</head>
<body>
<form id="Form1"
defaultbutton="SubmitButton"
defaultfocus="TextBox1"
runat="server">
<h3>DefaultButton and DefaultFocus Properties Example (2.0)</h3>
TextBox1:
<asp:textbox id="TextBox1"
autopostback="true"
runat="server">
</asp:textbox>
<br />
TextBox2:
<asp:textbox id="TextBox2"
autopostback="true"
runat="server">
</asp:textbox>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
runat="server">
</asp:button>
<asp:button id="CancelButton"
text="Cancel"
runat="server" OnClick="CancelButton_Click">
</asp:button>
<hr />
<asp:label id="Label1"
runat="Server">
</asp:label>
<asp:label id="Label2"
runat="Server">
</asp:label>
</form>
</body>
</html>
Hope it helps you!