Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > Override the search function from a Custom Search Box

Override the search function from a Custom Search Box

  • Stephen avatar

    Posted on Jan 12, 2012 (permalink)

    I need to create a custom search box for the site because the site needs to log the terms that customers are searching for. How can I achieve that? Is it possible to override the button click event for the search box? Thanks.

    Stephen

    Reply

  • Radoslav Georgiev Radoslav Georgiev admin's avatar

    Posted on Jan 16, 2012 (permalink)

    Hello,

    Since the search box makes a redirect to the search result page you will not be able to process the click postback event of the search button. The easiest way to achieve this is to do this in the control template for the Search Result control. Here is how you can get the catalog and the query passed to the search result:

    1) Open your website in VS and go to ~/Sitefinity/ControlTemplates/Search/SearchResult.ascx.
    2) Modify it as follows:
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Search" Namespace="Telerik.Search.WebControls.Admin"
        TagPrefix="sfSrc" %>
     
    <script runat="server" type="text/C#">
        protected void Page_Load()
        {
            var searchResultsControl = this.Parent.Parent;
            string query;
            if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["SearchQuery"]))
                query = HttpContext.Current.Request.QueryString["SearchQuery"];
            string catalogue;
            if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["IndexCatalogue"]))
                catalogue = HttpContext.Current.Request.QueryString["IndexCatalogue"];
        }
    </script>


    All the best,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > Override the search function from a Custom Search Box