[RESOLVED] Default button

I have a form that contains a text box and 02 buttons. 1. Search, 2. Clear.

The user types some text in the text box and then click the search button to search for the phrase users has entered in the text box. I wanted to make the searh button default, So that the user after entring text simply press the enter button to search for the text, instead of explicitly clicking the search button.


Hi, you use:

Form.DefaultSubmitButton = "mySearchButton";

HTH's 

You can also use "defaultbutton" property of form tag in aspx page to make any Button in your aspx page as default Button.


try this

Form.DefaultButton ="btnSubmit"


Hope this code helps you

<asp:Panel runat="server" ID="SearchPanel" DefaultButton="btn_search">


             <asp:TextBox ID="tb_search" runat="server"  ToolTip="Enter your search criteria" />
               
             <asp:Button ID="btn_search" runat="server" Text="search" Font-Names="Arial" OnClick="btn_search_Click" />

             <asp:Button ID="btn_Clear" runat="server" />
             
         </asp:Panel> 

Agree with Ramchandan.. You must use  Panel for achieve your functionality.


If you set Page's Default button property then for every unclicked thing it will fire DefaultButton Click which is wrong actually.



sayyed_kamran@hotmail.com

I wanted to make the searh button default, So that the user after entring text simply press the enter button to search for the text, instead of explicitly clicking the search button.

You can do that using Asp.net Focus API. please check out below link Focus API section :

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/tipstricks/default.aspx

thoughts on "[RESOLVED] Default button"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>