Kuzgun
Kuzgun

Reputation: 4737

Asp.Net multiple submit buttons, enter submits only the first

I have a few submit buttons in my ASP.NET page. Everything works fine, but when a user hits enter button always the first submit button works. I want to fire each submit button with corresponding fields but cannot have multiple forms. Is it possible to group them without using forms?

Upvotes: 3

Views: 4900

Answers (2)

Sain Pradeep
Sain Pradeep

Reputation: 3125

Please use DefaultButton property like this

<asp:Panel runat="server" DefaultButton="bt1">

<asp:TextBox runat="server" />
<asp:Button id="bt1" Text="Default" runat="server" />

</asp:Panel>

Please refer here :- ASP.NET DefaultButton Property

Upvotes: 5

Tim Schmelter
Tim Schmelter

Reputation: 460158

You don't need forms, just wrap the related controls in their own panels and use the Panel.DefaultButton property.

Use the DefaultButton property to indicate which button gets clicked when the Panel control has focus and the user presses the ENTER key. The DefaultButton can be set to the identifier for a Button control or any control that implements the IButtonControl interface except a LinkButton control.

Upvotes: 5

Related Questions