More in this section

Forums / Developing with Sitefinity / How do I make my search box control activate when the user presses the enter key?

How do I make my search box control activate when the user presses the enter key?

3 posts, 0 answered
  1. Troy Lawrence
    Troy Lawrence avatar
    56 posts
    Registered:
    07 Jan 2010
    11 Feb 2010
    Link to this post
    I used the Search control in Sitefinity and it works fine, but it only searches when the user clicks on the search button.  I want it to search when the user types in words and then hits the enter key on the keyboard.  How would I do this?

    Maybe you can see my search box at the link below?
    My Site
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Feb 2010
    Link to this post
    Hi Troy Lawrence,

    Get the search button and set it on focus. Sample code

    protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string script = "var btn = '" + this.Page.FindControl("searchButton").ClientID + "';";
            this.Page.ClientScript.RegisterStartupScript(
                this.GetType(),
                "focus",
                script, true);
        }


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    11 Feb 2010
    Link to this post
    I'm not sure if this will work, but in the past I've wrapped the control in an asp:panel and use the DefaultButton property to point to the search button.

    <asp:Panel ID="searchpanel" runat="server" DefaultButton="SearchButton">

    might be worth trying out, but I haven't tried it on the actual search box, because mine works when I press enter.
Register for webinar
3 posts, 0 answered