Home > Articles > ASP.NET Articles > How to post a form data using Enter key in ASP.NET?

How to post a form data using Enter key in ASP.NET?

by Thamil   on Aug 28, 2014   Category: ASP.NET  | Level: Beginner  |  Views: 3328    |  Points: 100   
Like this article? Bookmark and Share:
In this article I will explain how to submit a form when user clicks on enter key in asp.net application.



End users always preferred the Enter key to submit the form, however we provide the submit button in the page because it’s easiest way to post the data for them. Microsoft provided the facility to handle the form submission through enter key by using Dafultbutton property in the form.

In Asp.net application we may use single or more submit button to post the data in the form, so we need to handle two scenarios in this case

Single submit button in the form:

If form has few textbox and one submit button then add the Defaultbutton property in the form tag and assign the button id to Defaultbutton property as like below.

<form id="form1" runat="server" defaultbutton="btnSubmit">


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />




More than one submit button inside the asp.net panel:

Suppose, form has more than one submit buttons and placed inside the panel control. Say for ex form has two panel controls and submit buttons are placed inside the each panel, which is used to post the specific panel data to the server. So now we need to specify the defaultbutton property at the Panel level in the Panel tag as like below.

<form id="form1" runat="server">

<asp:Panel ID="Panel1" runat="server" DefaultButton="btnPanel1">


<asp:TextBox ID="txtName" runat="server"></asp:TextBox>

<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>

<asp:Button ID="btnPanel1" runat="server" Text="Submit" OnClick="btnPanel1_Click" />



<asp:Panel ID="Panel2" runat="server" DefaultButton="btnPanel2">


<asp:TextBox ID="txtEmpName" runat="server"></asp:TextBox>

<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>

<asp:Button ID="btnPanel2" runat="server" Text="Submit" OnClick="btnPanel2_Click" />




Enter the input to txtName & txtPwd in the Panel1 and press on Enter key then btnPanel1_Click event will be triggered and execute the code. Same fill the txtEmpname and txtAge and press on Enter key the btnPanel2_Click event will be triggred.

I hope this article would helpful when you post a form data by click on Enter key in asp.net form and panel. Provide your suggestions and comments.

Like this article? Bookmark and Share:

Most viewed Articles

User Comments

No response found, be the first to review this article.

Submit feedback about this article

Please sign in to post feedback

Latest Posts