More in this section

Forums / Developing with Sitefinity / Use of SimpleControl in SF 3.6

Use of SimpleControl in SF 3.6

3 posts, 0 answered
  1. James Reategui
    James Reategui avatar
    22 posts
    Registered:
    14 Oct 2008
    05 Mar 2009
    Link to this post
    Hi,
    So I'm trying to build standalone generic controls that would be used on the public side of my site and I was between using the ViewModeUserControl class or the SimpleControl class.

    What is the difference with a SimpleControl? When should it be used? I couldn't find docs pertaining to it yet in the blog.

    Note that in my case I need to build the controls in a separate class library and then have the compiled DLL be consumed by a few different SF application projects. That's why I'm not just using standard ascx user controls.

    thanks
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    06 Mar 2009
    Link to this post
    Hello James,

    SimpleControl inherits from CompositeControl class and provides a base implementation for controls that are not Views. So, you could use it for your public controls which do not need more than one template. First of all you need to declare a constant pointing out to the embedded template:

    private const string CategoriesTreeTemplateName = "Telerik.Cms.Engine.Resources.ControlTemplates.Frontend.CategoriesTree.ascx"

    Then, you should override LayoutTemplatePath and LayoutTemplateName properties:

            /// <summary> 
            /// Gets or sets the path to a custom layout template for the control. 
            /// </summary> 
            [WebSysTemplate(CategoriesTree.CategoriesTreeTemplateName, 
                "CategoriesTree_Template_Desc""/Generic_Content/"true"2008-01-19")] 
            [Category("Appearance"), Themeable(false), DefaultValue("")] 
            public override string LayoutTemplatePath 
            { 
                get 
                { 
                    return base.LayoutTemplatePath; 
                } 
                set 
                { 
                    base.LayoutTemplatePath = value; 
                } 
            } 
     
            /// <summary> 
            /// Gets the name of the embedded layout template. This property must be overridden to provide the path (key) to an embedded resource file.  
            /// </summary> 
            public override string LayoutTemplateName 
            { 
                get 
                { 
                    return CategoriesTree.CategoriesTreeTemplateName; 
                } 
            } 

    Also, note that you do not have to override CreateChildControls method directly. Instead, you should use InitializeControls which will be called at the opportune time for your controls to be initialized:

            /// <summary> 
            /// Gets the control title. 
            /// </summary> 
            /// <value>The control title.</value> 
            protected virtual ITextControl ControlTitle 
            { 
                get { return (ITextControl) base.Container.GetControl<Control>("controlTitle"true); } 
            } 
     
             
            /// <summary> 
            /// Initializes all controls instantiated in the layout container. This method is called at appropriate time for setting initial values and subscribing for events of layout controls. 
            /// </summary> 
            /// <param name="controlContainer">The container that will host the template of this control.</param> 
            protected override void InitializeControls(Control controlContainer) 
            { 
                base.InitializeControls(controlContainer); 
     
                this.ControlTitle.Text = "Test"
     
            } 

    Regarding ViewModeUserControl, it is identical with ViewModeControl. The deference is in the fact that ViewModeControl class inherits from CompositeControl class, while ViewModeUserControl class inherits from UserControl class. For details on this matter refer to the following blog post: Sitefinity 3.6 new backend architecture - Architectural overview

    Greetings,
    Pepi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    06 Mar 2009
    Link to this post
    Hi Pepi,

    Could you make one small sample that expose one News item and thumbnail FontSide like initial version 3 in one UC with no design and only one template ListPageDetail very simplified, title and thumbnail for FrontSide, to add in Toolbox as dll. I'm affaid but I'm not understand your sample. Thanks. 
Register for webinar
3 posts, 0 answered