More in this section

Forums / Developing with Sitefinity / Modify Search Results When 0 Returned

Modify Search Results When 0 Returned

3 posts, 1 answered
  1. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    10 Nov 2009
    Link to this post
    Hi All,

    I am wanting to modify the search result page, so that when there are no results I can display a more helpfull message instead of the default 'found 0 pages' etc.

    I see that this line is where that comes from:

    <div class="resStats"><asp:Literal ID="ResultsStats" runat="server">Found <strong>{0}</strong> pages for "<strong>{1}</strong>" </asp:Literal></div>

    Can I acces the result set and check for 0 records? If so how? as I am not sure how to access the '{0}' of the previous code.

    Any help is appreciated.

    Thanks

    Jodie

     
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 Nov 2009
    Link to this post
    Hi Jodie,

    Thank you for using our services.

    You can edit the control template for the Search Result control. It is located in ~/Sitefinity/Admin/ControlTemplates/Search/SearchResult.ascx. Here is a sample how you can modify it. Bind to the prerender event of the results repeater and if there are no results display your message:
    <%@ 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" %>
     
    <sfWeb:CssFileLink ID="CssFileLink1" FileName="~/Sitefinity/ControlTemplates/Search/searchCommonLayout.css" Media="screen" runat="server" />
     
    <h2><asp:Literal ID="ResultsStats" runat="server">Found {0} pages for "{1}" </asp:Literal></h2>
    <asp:Literal ID="NoResults" runat="server" Visible="false"></asp:Literal>
    <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            rptResults.PreRender += new EventHandler(rptResults_PreRender);
        }
     
        void rptResults_PreRender(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            if (rptResults.Items.Count == 0)
            {
                ResultsStats.Visible = false;
                this.NoResults.Visible = true;
                this.NoResults.Text = "No results were found";
            }
        }
         
    </script>

    This should do the trick.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    15 Nov 2009
    Link to this post
    Hi Radoslav,

    Sorry for the belated response. Yes you are right this will do the trick.

    Thanks alot

    Jodie
Register for webinar
3 posts, 1 answered