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

Forums / Developing with Sitefinity / Possible to viewmap SearchBox and SearchResults

Possible to viewmap SearchBox and SearchResults

6 posts, 0 answered
  1. Trevor
    Trevor avatar
    17 posts
    Registered:
    18 Nov 2010
    22 Dec 2010
    Link to this post
    I am busy trying to create another template for the SearchBox and SearchResults to use and would like to find out if it is possible to map the viewsettings (in the ControlsConfig.xml) as follows:

    <controlsConfig>
        <viewMap>
            <viewSettings hostType="Telerik.Search.WebControls.SearchBox" layoutTemplatePath="~/Modules/Search/SearchBox.ascx" />
            <viewSettings hostType="Telerik.Search.WebControls.SearchResult" layoutTemplatePath="~/Modules/Search/SearchResult.ascx" />
        </viewMap>
    </controlsConfig>

    With the above code Sitefinity seems happy but it's still not display the new templates and reverts back to the default version.

    Thank you very much in advance for your assistance! 
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Dec 2010
    Link to this post
    Hi Trevor,

    SearchBox and SearchResults control use external templates from Sitefinity/ControlTemplates/Search. We have not embedded them and there is not configuration that allows you to do this. Both the controls have public properties (LayoutTemplatePath) that you can set another template.

    Greetings,
    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. Trevor
    Trevor avatar
    17 posts
    Registered:
    18 Nov 2010
    22 Dec 2010
    Link to this post
    Hi Ivan,

    Thank you for the quick reply. I thought that might be the case. Is there anyway to default the control to use the other template or would that need to be set on a each use of the control?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Dec 2010
    Link to this post
    Hi Trevor,

    The template has to be set per control instance. You can do it from the ControlsConfig only if you create a custom controls that inherit from SearchBox and SearchResult.

    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
  5. Trevor
    Trevor avatar
    17 posts
    Registered:
    18 Nov 2010
    22 Dec 2010
    Link to this post
    Thank you very much for your time and assistance Ivan, really appreciate it! I know I might be pushing my luck but you don't have a sample project to show me how to implement inheritance for a custom module from a built-in one... basically my a Custom SearchBox from the built-in SearchBox?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Dec 2010
    Link to this post
    Hello Trevor,

    Here is a sample implementation. You have to use the custom template path property exposed in the control. You can separate the classes, because currently they all are inside one cs file.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Search.WebControls;
    using Telerik.Web;
    using System.Web.UI.HtmlControls;
    using Telerik.Framework.Web;
    using Telerik.Search;
    using Telerik.Samples.Search;
     
    /// <summary>
    /// Summary description for SearchBoxCustom
    /// </summary>
    ///
    [System.ComponentModel.ToolboxItem(typeof(SearchBoxToolboxItemCustom))]
    public class SearchBoxCustom : SearchBox
    {
        public SearchBoxCustom()
        {
        }
     
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }
     
     
        public override System.Web.UI.ITemplate LayoutTemplate
        {
            get
            {
                    if ( this.layoutTemplate == null )
                        this.layoutTemplate = ControlUtils.GetTemplate<DefaultTemplate>(this.LayoutTemplatePathCustom);
                    return this.layoutTemplate;
               
            }
            set
            {
                base.LayoutTemplate = value;
            }
        }
     
        [WebSysTemplate(SearchBoxCustom.SearchBoxCustomTemplateName, "SearchBoxCustom_Desc", "/Search", true, "2010-12-22")]
        public string LayoutTemplatePathCustom
        {
            get
            {
                object obj = this.ViewState["layoutTemplatePath"];
                if (obj != null)
                    return (string)obj;
                return IndexDataProvider.DefaultProviderInstance.SearchBoxTemplate;
            }
            set
            {
                this.ViewState["layoutTemplatePath"] = value;
            }
        }
         
     
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            HtmlGenericControl control = new HtmlGenericControl();
            string url = string.Empty;
            url = Page.ClientScript.GetWebResourceUrl(typeof(Telerik.Search.WebControls.SearchBox), "Telerik.Search.Resources.Search.js");
            if (!String.IsNullOrEmpty(url))
            {
                control.TagName = "script";
                control.Attributes.Add("src", url);
                control.Attributes.Add("type", "text/javascript");
                this.Page.Header.Controls.Add(control);
            }
        }
     
        private const string SearchBoxCustomTemplateName =
               "Telerik.Sitefinity.Samples.Resources.ControlTemplates.SearchBoxCustom.ascx";
    }
     
    public class SearchBoxToolboxItemCustom : Telerik.Web.ToolboxItem
    {
            #region Construction
             
         public SearchBoxToolboxItemCustom()
            : base(typeof(SearchBoxCustom))
            {
                base.DisplayName = "SearchBox_DisplayName";
                base.Description = "SearchBox_Description";
     
            }
            #endregion
    }
     
     
    namespace Telerik.Samples.Search
    {
        [AttributeUsage(AttributeTargets.Property)]
        internal class WebSysTemplate : EmbeddedTemplateAttribute
        {
            public WebSysTemplate(string resourceName, string description
                , string defaultExtPaht, bool isFrontEnd, string lastModified)
                : base(resourceName, description, defaultExtPaht, isFrontEnd, lastModified)
            {
            }
     
            public override string Description
            {
                get
                {
                    return "some desc";
                }
            }
     
            public override object TypeId
            {
                get
                {
                    return typeof(EmbeddedTemplateAttribute);
                }
            }
        }
    }


    Kind regards,
    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
Register for webinar
6 posts, 0 answered