23. September 2008 15:18
/
0
/
Comments (3)
Today I learned something new about ASP.NET. I learned that you can have multiple default buttons based on where you are in the form. For example if you have a form with a Save button and other buttons to do some server side checking you can set the default button of the form to be the Save button and use the DefaultButton property of the Panel container to specify which button should be the default button for that specific part of the page.
<form id="form1" runat="server" defaultbutton="btnSave">
<asp:TextBox id="tb" runat="server" />
<asp:Panel id="pnlOne" runat="server" DefaultButton="btnAdd">
<asp:TextBox id="tb1" runat="server" /><asp:Button id="btnAdd" runat="server" text="Add" />
</asp:Panel>
<asp:Panel id="pnlTwo" runat="server" DefaultButton="btnDelete">
<asp:TextBox id="tb2" runat="server" /><asp:Button id="btnDelete" runat="server" text="Delete" />
</asp:Panel>
<asp:Button id="btnSave" runat="server" text="Save" />
</form>
So the code above has 3 default buttons. If you are standing in the “tb” TextBox and press enter the “btnSave” will be clicked. When you press enter while on the “tb1” TextBox the “btnAdd” will execute and finally if you are standing in the “tb2” TexBox the “btnDelete” will be clicked.
Everyday you learn something new is a good day.
Happy Programming!
235147ec-5379-4b64-9872-e9a9d534523c|0|.0|27604f05-86ad-47ef-9e05-950bb762570c