In this article we will explain how to post form on enter button press in with example.


Suppose, you want to press/click submit button on Enter button press in keyboard or you are trying to post the form on Enter button pressing in keyboard. In, to achieve this functionality we need to set "Defaultbutton" property either in Form.

Form DefaultButton Property


Exapmle of Form DefaultButton Property

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
     Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
 <html xmlns="">
<head runat="server">
   <title>submit form</title>
   <form id="form1" runat="server" defaultbutton="btnSubmit">
       UserID: <asp:TextBox ID="txtUserID" runat="server"/>
       Password: <asp:TextBox ID="txtUserpwd" runat="server"/>
        <asp:Button ID="btnSubmit" runat="server"  Text="Submit"
           OnClick="btnSubmit_Click" style="height: 25px"/>

We specify the defaultbutton property at the Form level in the form tag when there is only one Submit Button for post back.

In above example I explain the default submit behavior of form. I hope after reading you will understand it.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like