Skip to main content

Set Search Text Box Default

Ways to set search text box default is given below:

  txtSearch.Value  = "Search keywords";
  txtSearch.Attributes.Add("onfocus", "if (this.value == 'Search keywords') this.value = '';");
  txtSearch.Attributes.Add("onBlur", "if (this.value == '') this.value = 'Search keywords';");
  this.Page.Form.DefaultButton = imgSearch.UniqueID;
 
Alternatively, you could wrap a panel control  around your tags and set the default control on 
that Panel.
 
 <asp:Panel ID="pnlsearch" runat="server" DefaultButton="imgSearch">
                    <div id="search-drop">
                        <div class="search">
                            <div class="global-search-input">
                                <input type="text" id="txtSearch" runat="Server" class="text" name="search" onfocus="if (this.value == 'Search..') this.value = '';" onblur="if (this.value == '') this.value = 'Search..';" value="Search..">
                                <asp:Literal ID="litRedirect" runat="server" />
                                <asp:ImageButton ID="imgSearch" ImageUrl="/Style Library/PitchIn/images/search-icon.png" CssClass="searchsubmit" runat="server" OnClick="imgSearch_Click" />
                            </div>
                        </div>
                        <div class="close"></div>
                    </div>
 </asp:Panel>  

I will add to the list as I remember the options I have used in the past.

Comments