Introduction:

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

Description:

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 asp.net, to achieve this functionality we need to set "Defaultbutton" property either in Form.

Form DefaultButton Property

defaultbutton="btnSubmit"

Exapmle of Form DefaultButton Property

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
     Inherits="WebApplication1.WebForm1" %>
 
<!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>submit form</title>
    </head>
<body>
   <form id="form1" runat="server" defaultbutton="btnSubmit">
    <div>
       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"/>
</div>
</form>
</body>
</html>

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.

comments


Leave a comment

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

You may also like