Hi mahjoubi,
You need to add a Panel and inside add TextBox and Button.
Then set the Panel control DefaultButton property with the Button control Id.
When Enter key pressed the specified Button Click event will be executed.
Refer below example.
HTML
<asp:Panel ID="pnl2" runat="server" DefaultButton="btnSubmit1">
<asp:TextBox ID="txtBox1" runat="server" />
<asp:Button ID="btnSubmit1" Text="Save" runat="server" OnClick="btnSubmit1_Click" />
</asp:Panel>
<br />
<asp:Panel ID="pnl1" runat="server" DefaultButton="btnSubmit2">
<asp:TextBox ID="txtBox2" runat="server" />
<asp:Button ID="btnSubmit2" Text="Save" runat="server" OnClick="btnSubmit2_Click" />
</asp:Panel>
Code
C#
protected void btnSubmit1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Button 1 clicked');", true);
}
protected void btnSubmit2_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Button 2 clicked');", true);
}
VB.Net
Protected Sub btnSubmit1_Click(ByVal sender As Object, ByVal e As EventArgs)
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Button 1 clicked');", True)
End Sub
Protected Sub btnSubmit2_Click(ByVal sender As Object, ByVal e As EventArgs)
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Button 2 clicked');", True)
End Sub
Screenshot