The Simple Control class

The Simple Control class

Posted on April 23, 2009 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

Well, we said that the documentation is completed, but this does not mean that we can't add new things to it!

 

[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]

SimpleControl class


This is one of the three pivot classes in the new backend architecture. The other two – ViewModeControl and ViewModeUserControl are related to the back-end of a module – views. However, every module has public controls.
If you develop a pluggable module, then you will discover that you often implement the same functionality over and over again. And namely:
  • Localization
  • Embedded templates
This functionality is provided by SimpleControl.  And if you have already adopted the new back-end architecture, you will want to inherit this class in all your public controls. Actually, we do so for the built-in controls in Sitefinity which are not GenericContent-based (they derive from ContentView).

 

NOTE:

 


No matter how useful, sometimes you will not need to inherit this class. Take for example the GenericContent control. All it does is simply display some formatted text - nothing else. Therefore, it needs no template. It needs no localization, as the content items it displays are localizable themselves, and if they are not shared, the page is localizable itself.

 


END NOTE

 

NOTE:

 


Since SimpleControl is designed to be like ViewModeControl, you will find that most of their properties are named alike and serve the same purpose.

 


END NOTE

 

Usage


Here is, for example, how our PollBox control is declared:
public class PollBox : SimpleControl, IEmptyControl 

Most often you will end up overriding LayoutTemplateName and LayoutTemplatePath in order to support embedded templates.

 

Properties


  • protected virtual string AdditionalTemplateKey { get; }
    Returns the key for loading additional templates. Generally, this property is overridden if there is a need for it. Typically, this property is overridden to supply the name of the current provider. You can find more information on loading additional templates in this article.
  • public virtual Type AssemblyInfo { get; set; }
    Gets or sets the assembly info on the assembly from which the embedded resources should be loaded. The property is of type Type and in order to set it, it is enough to set it to any Type which is located in the assembly with the embedded templates.
  • public virtual Type LocalizationAssemblyInfo { get; set; }
    Similar to the AssemblyInfo, LocalizationAssemblyInfo gets or sets info on the assembly in which localization messages are embedded. The property is of type Type and in order to set it, it is enough to set it to any Type which is located in the assembly with the embedded localization resources.
  • protected virtual GenericContainer Container { get; }
    Views will always instantiate the template (regardless of how was the template declared) inside of the Container property. The Container property is of type GenericContainer, which provides simple and fast way for accessing controls inside of the template through it’s GetControl function, like it is demonstrated here:
    RadGrid dataGrid = base.Container.GetControl<RadGrid>("dataGrid"true); 
    NOTE:

    Sometimes you will still want to use the old approach and define a container yourself. It is appropriate to do so if you have lots of exposed controls in your template and you don’t want your class to be bloated with UI controls. It is a good idea to be familiar with the best practices of exposing template controls.

    END NOTE
  • public virtual ITemplate LayoutTemplate { get; set; }
    Gets or sets the template to be used by this View. To learn more about different types of templates take a look at this article.

    NOTE:

    You will probably never need to override this property. If you do, you will most probably have to override Container as well

    END NOTE
  • public virtual string LayoutTemplateName { get; }
    Gets the name of the embedded template to be used by the View. To learn more about different types of templates take a look at this article.

    NOTE:

    You will want to override this property if you want embedded template support. This will point to the virtual path of the embedded template.

    END NOTE
  • public virtual string LayoutTemplatePath { get; set; }
    Gets or sets the path to the external template to be used by this View. To learn more about different types of templates take a look at this article.

    NOTE:

    You will want to override this property if you want embedded template support. You will also have to apply EmbeddedTemplateAttribute (or a derived attribute) to your overridden property.

    END NOTE

Methods


  • protected override void CreateChildControls()
    You should never override this. If you do, templates won’t work. To initialize your child controls, use InitializeControls instead
  • protected virtual GenericContainer CreateContainer()
    You will probably never need to use this. Used to create a new instance of your container. Used if you want to use your own class container that inherits GenericContainer.
  • protected virtual ITemplate CreateLayoutTemplate(Type assemblyInfo, Type localizationAssemblyInfo)
    Initializes AssemblyInfo and LocalizationAssemblyInfo properties and loads your template. Unless you have compelling reason to do so, you shouldn’t override this.
  • protected virtual void InitializeControls(Control controlContainer)
    This is where you should initialize your child controls. Simply put, replaces CreatChildControls(). Here is an example:
    protected override void InitializeControls(Control viewContainer) 
        if (!this.Page.IsPostBack) 
        { 
            this.ReportForm.Visible = true
            this.ReportCreatedPanel.Visible = false
        } 
        this.SaveReport.Click += this.SaveReport_Click; 
        this.BackToReportsList.NavigateUrl = this.GetListCommand(); 



progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation