How to set the Default Button in ASP.NET Web Form


You have an ASP.NET Web Form with some button controls and you want to make one of those button default button of the form so that when use press Enter key in any control such as TextBox the default button click event fire automatically.

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

   <asp:TextBox ID="Textbox1" runat="server" /> 
   <asp:TextBox ID="Textbox2" runat="server" /> 

   <asp:Button ID="FirstButton" runat="server" Text="Default Button" /> 
   <asp:Button ID="SecondButton" runat="server" Text="Non Default Button" /> 

</form>

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments