Base control used to contain a template. Ensures that if the template has been instantiated or the Controls collection has been accessed the template cannot be set again.
Definition
Namespace:Telerik.Web.UI
Assembly:Telerik.Web.UI.dll
Syntax:
public class SingleTemplateContainer : Panel, IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor, IAttributeAccessor, INamingContainer
Inheritance: objectControlWebControlPanelSingleTemplateContainer
Implements:
Inherited Members
Example:
- Into an existing WebControl add a readonly property and
a member for the template container
private SingleTemplateContainer _contentContainer;
[Browsable(false)] public SingleTemplateContainer ContentContainer { get { EnsureChildControls(); return _contentContainer; } }
- Override CreateChildControls() and instantiate the SingleTemplateContainer.
The parameter is a reference to the instantiating control (used when throwing exceptions).
protected override void CreateChildControls() { base.CreateChildControls();
_contentContainer = new SingleTemplateContainer(this);
_contentContainer.ID = "Content";
Controls.Add(_contentContainer);
}
- Add read/write property for the template. You will need the TemplateContainer
attribute in case if you override SingleTemplateContainer in order to add properties, accessible during the databinding.
//[TemplateContainer(typeof(SingleTemplateContainer))] [PersistenceMode(PersistenceMode.InnerProperty)] [TemplateInstance(TemplateInstance.Single)] [Browsable(false)] public ITemplate ContentTemplate { get { EnsureChildControls(); return ContentContainer.Template; } set { EnsureChildControls(); ContentContainer.Template = value; } }
Properties
public override ControlCollection Controls { get; }
Overrides:
Methods
protected override void CreateChildControls()
Overrides:
protected virtual void InstantiateTemplate()