+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / SearchResults.ascx Control Template

SearchResults.ascx Control Template

2 posts, 0 answered
  1. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    04 Nov 2009
    Link to this post
    Hey there,

    We're customizing the Search Results control template with the key objective being to duplicate the pager on the top of the search results as well as the bottom.

    Is there a way that we can achieve this?

    Regards,
    Jacques
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Nov 2009
    Link to this post
    Hello J.Hov,

    In the code of SearchResults there is only one pager control initialized and bound. You need to create a custom control that derives from SearchResults. Then create a template that has the header pager. Override CreateChildcontrols method and after the base implement the logic for the header pager.

    Below is a sample code:

    public int Pager2PostsPerPage
        {
            get
            {
                object obj = this.ViewState["Pager2PostsPerPage"];
                if (obj != null)
                    return (int)obj;
                return 10;
            }
            set
            {
                this.ViewState["Pager2PostsPerPage"] = value;
            }
        }
         
        protected int Pager2CurrentPage
        {
            get
            {
                object o = this.ViewState["_Pager2CurrentPage"];
                if (o == null)
                    return 1;
                else
                    return (int)o;
            }
            set
            {
                this.ViewState["_Pager2CurrentPage"] = value;
            }
        }
         
         
        protected override void CreateChildControls()
        {
             
           
            base.CreateChildControls();
            //just for demonstration
            int totalItems = 10;
            int numberOfPages = (this.Pager2PostsPerPage== 0) ? 1 : (int)Math.Ceiling((double)totalItems / (double)this.Pager2PostsPerPage);
     
            if (numberOfPages == 0 && totalItems > 0)
                numberOfPages = 1;
     
            this.pager2.SelectedPageChanged += new EventHandler<EventArgs>(pager2_SelectedPageChanged);
            this.pager2.PageCount = numberOfPages;
            this.pager2.SelectedPage = this.CurrentPage;
        }
     
        void pager2_SelectedPageChanged(object sender, EventArgs e)
        {
            this.Pager2CurrentPage= ((Pager)sender).SelectedPage;
            this.ChildControlsCreated = false;
        }

    Greetings,
    Ivan Dimitrov
    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.
2 posts, 0 answered