Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hi
I want to make the button as default, i mean i want to fire it when i click enter button on key board


Tx in advance
Posted

Try this.
<form id="form1" runat="server" defaultbutton="Button1"></form>
 
Share this answer
 
Comments
thatraja 11-Aug-11 6:23am    
Right, 5!
nagendrathecoder 11-Aug-11 7:16am    
Good answer.
Hi,

If you want to have multiple default buttons (for example you have a search-button and a contact form on the same page), you could use it this way:

ASP.NET
<form runat="server">
	<asp:Panel runat="server" DefaultButton="btnSearch">
		<asp:TextBox ID="tbSearchText" runat="server" />
		<asp:Button ID="btnSearch" runat="server" Text="Search" />
	</asp:Panel>

	<asp:Panel runat="server" DefaultButton="btnSendContact">
		<asp:TextBox ID="tbFirstname" runat="server" />
		<asp:TextBox ID="tbLastname" runat="server" />
		<asp:TextBox ID="tbComment" runat="server" />
		<asp:Button ID="btnSendContact" runat="server" Text="Submit" />
	</asp:Panel>
</form>


Using a panel around some server-controls renders a div HTML tag and adds some JavaScript which allows the default-button firing.

If you ask yourself why you have to use this, thats simple: because ASP.NET only allows one form HTML tag, you cannot create multiple forms on one page, so you cannot use the HTML feature of the default button firing on each form (because the browser would just fire the first button it finds on the page).

Hope this helps.


Best regards and happy coding,
Chris
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900