We can assign the ID value of a button control to DefaultButton property in <form> element in order to send the form information filled by the user to the server easily by button object in ASP.NET pages. By this way, the information given in the form can be sent to server when user push Enter key from the keyboard without clicking the button. If there are different forms are included in our page (for example there is a login form at the left of the page and sign up form at the right of the page), how can we make the related button clicked when the user pushes Enter key from the keyboard after filling one of the forms? We can handle this situation again by using DefaultButton property but not the DefaultButton property of <form> element!
Firstly, we must locate both of the forms in Panel controls for solving this situation. Actually, Panel control has DefaultButton property too. Therefore, the forms will function as we want, if we assign the ID value of the button that is included inside of the panel and will do the Submit operation, to the DefaultButton property of the relevant Panel. If you have another form besides these panels and if you want the submit button in this form to be triggered when the Enter key is pushed outside the panels, you can use DefaultButton property of <form> element anyway. When you test the code snippet given below in your project, you can clearly see the situation.
Default.aspx
<form id="form1" runat="server" defaultbutton="button1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" Text="Button-1" OnClick="btn_Click" />
<br />
<asp:Panel ID="panel1" runat="server" BackColor="LightGreen" DefaultButton="button2" Width="300">
<asp:TextBox ID="text1" runat="server"></asp:TextBox>
<asp:Button ID="button2" runat="server" Text="Button-2" OnClick="btn_Click" />
</asp:Panel>
<asp:Panel ID="panel2" runat="server" BackColor="LightBlue" DefaultButton="button3" Width="300">
<asp:TextBox ID="text2" runat="server"></asp:TextBox>
<asp:Button ID="button3" runat="server" Text="Button-3" OnClick="btn_Click" />
</asp:Panel>
</form>
Default.aspx.cs
protected void btn_Click(object sender, EventArgs e)
{
Response.Write("Clicked button: " + ((Button)sender).Text);
}