How to create a default button among list of buttons control in asp.net

Following HTML code snippet will help you to achieve it.

 

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

        <asp:Panel ID="pnlIndex" runat="server" DefaultButton="btnGo2">

            <table cellpadding="0" cellspacing="0" border="0" width="1002px" height="100%" id="tblMain"

                align="center">

                <tr align="left">

                    <td align="left">

                        <asp:TextBox runat="server" Width="100px" MaxLength="14" ID="txtUserName" AutoCompleteType="Disabled"

                            CssClass="TxtBox"></asp:TextBox>

                    </td>

                </tr>

                <tr align="left">

                    <td align="left">

                        <asp:Button ID="btnGo1" runat="server" Width="30" Text="Go1" BackColor="#8b95ae"

                            OnClick="btnGo1_Click1"></asp:Button>

                    </td>

                </tr>

                <tr align="left">

                    <td align="left">

                        <asp:Button ID="btnGo2" runat="server" Width="30" Text="Go2" BackColor="#8b95ae"

                            OnClick="btnGo2_Click1"></asp:Button>

                    </td>

                </tr>

                <tr align="left">

                    <td align="left">

                        <asp:Button ID="btnGo3" runat="server" Width="30" Text="Go3" BackColor="#8b95ae"

                            OnClick="btnGo3_Click1"></asp:Button>

                    </td>

                </tr>

            </table>

        </asp:Panel>

    </form>

 

Explanation

 

As you can see in above code snippet, we have three buttons as btnGo1, btnGo2, btnGo3.

Now say we like to make btnGo2 as default button.

 

We created a panel and declare the default button Id and put the remaining code inside the pannel.

 

So now btnGo2 is the default for your page. You can change it by assigning other button Id inside pannel tag.