In this article I will explain with an example, how to Call (Trigger) Button Click event on Enter Key Press in ASP.Net.
There is no server side key press event for an ASP.Net TextBox, hence using a Panel and its Default Button trick we can achieve the same.
 
HTML Markup
The HTML Markup consists of an ASP.Net TextBox control and a Button control wrapped inside an ASP.Net Panel control.
The Button is set as the DefaultButton for the Panel. When a enter key is pressed in any TextBox inside Panel with a DefaultButton then the Button Click event handler is raised. To know more about it, please refer my article Setting Default Button in ASP.Net Web Page.
<asp:Panel runat="server" DefaultButton="Button1">
    Name:<asp:TextBox ID="txtName" runat="server" />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
</asp:Panel>
 
Below is the click event handler for the Button control discussed above. The text entered in the TextBox is displayed in Browser using JavaScript Alert message box.
C#
protected void Button1_Click(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Name: " + txtName.Text + "');", true);
}
 
VB.Net
Protected Sub Button1_Click(sender As Object, e As System.EventArgs)
    ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Name: " & txtName.Text & "');", True)
End Sub
 
 
Screenshot
Call (Trigger) Button Click event on Enter Key Press in ASP.Net
 
 
Demo
 
 
Downloads