How to change default button of a form

Often, we have condition when we have multiple forms on a page which have multiple submit buttons as well. Whenever, you press enter on any text box it will call the command button which is at top most sequence of command buttons.

So, to overcome this problem here is the little code. Take your each set of fields and button in a panel and specify the default Button Property. In the example below I have a form which have two buttons one is command button and another is an image button and I am setting the second button of the sequence to get called each time enter key press on the panel. (rather then the top most)

   1: <asp:Panel ID="pnl1" runat="server" DefaultButton="ImageButton1">
   2:         <asp:TextBox ID="TextBox1" runat="server">
   3:         </asp:TextBox>
   4:         <asp:Button ID="Button1" runat="server" Text="Submit" />
   5:         <asp:ImageButton ID="ImageButton1" runat="server" />
   6:     </asp:Panel>
Published Monday, January 05, 2009 5:44 PM by aghausman12
Filed under: ,

Comments

# How to change default button of a form - Agha Usman

Monday, January 05, 2009 8:10 AM by How to change default button of a form - Agha Usman

Pingback from  How to change default button of a form - Agha Usman

# How to change default button of a form | IT Questions

Monday, January 12, 2009 11:28 AM by How to change default button of a form | IT Questions

Pingback from  How to change default button of a form | IT Questions

# re: How to change default button of a form

Wednesday, March 11, 2009 6:16 PM by milindsaraswala

Good Man I was searching and u gave me the right way :)

# re: How to change default button of a form

Monday, July 20, 2009 2:35 AM by nripinbabu@msn.com

Love your code mate Keep up the Great Work!!!!

# re: How to change default button of a form

Tuesday, April 05, 2011 12:48 AM by weblogs.asp.net

How to change default button of a form.. Dandy :)

Leave a Comment

(required) 
(required) 
(optional)
(required)