Class UserControlBase
A utility class to simplify the code in user controls.
Inheritance
Implements
Namespace: EPiServer
Assembly: EPiServer.Cms.AspNet.dll
Version: 11.20.7Syntax
public class UserControlBase : UserControl, IRenderSettings
Remarks
UserControlBase is to EPiServer Web user controls what PageBase is to EPiServer page templates - it provides access to the EPiServer infrastructure. Letting a Web user control inherit EPiServer.UserControlBase instead of the default UserControl turns the standard User Control class into a fully-fledged EPiServer Universe member, with access to EPiServer Web pages and current configuration settings, among other things.
By inheriting from the UserControlBase class you do not have to cast the Page property of the UserControl class to a PageBase class. Instead use the CurrentPage and the other members like you would directly from PageBase or TemplatePage.
The purpose is to give access to frequently used methods and properties of the PageBase class without having to cast the Page property.
note
This class does not implement IPageSource, even though it mimics the interface by having all the IPageSource methods. The reason for this is that if UserControlBase really implemented IPageSource, it would cause controls such as Property to become contained and non-editable via dope.
Examples
The following example demonstrates how to inherit from the <strong>UserControlBase</strong> class.
// Visual Studio.NET adds user controls with this inheritance
public abstract class Header : System.Web.UI.UserControl
{
// ...
}
// Change it to inherit from UserControlBase
public abstract class Header : UserControlBase
{
// ...
}</code></pre>
Constructors
UserControlBase()
Initializes a new instance of the UserControlBase class.
Declaration
public UserControlBase()
Properties
CurrentPage
Get the page data for the current page.
Declaration
public virtual PageData CurrentPage { get; set; }
Property Value
Type | Description |
---|---|
PageData |
Remarks
LocalizationService
The localizationService used by the various Translate methods on UserControlBase.
Declaration
protected virtual LocalizationService LocalizationService { get; }
Property Value
Type | Description |
---|---|
LocalizationService |
Locate
Gets the object used to resolve services part of the public API.
Declaration
public ServiceLocationHelper Locate { get; }
Property Value
Type | Description |
---|---|
ServiceLocationHelper |
PageBase
Return the executing Page cast to a PageBase class.
Declaration
public virtual PageBase PageBase { get; }
Property Value
Type | Description |
---|---|
PageBase |
Remarks
Only PageBase differs between UserControlBase and PageBase. All the other properties and methods have the same purpose in both PageBase and UserControlBase.
RenderSettings
Dictionary of key values that can be used to customize the rendering of the property.
Declaration
public IDictionary<string, object> RenderSettings { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Object> | The render settings. |
Methods
GetChildren(PageReference)
Returns a PageDataCollection of child Pages to specified PageReference (from IPageSource).
Declaration
public virtual PageDataCollection GetChildren(PageReference pageLink)
Parameters
Type | Name | Description |
---|---|---|
PageReference | pageLink |
Returns
Type | Description |
---|---|
PageDataCollection |
GetPage(PageReference)
Returns the corresponding PageData object to the supplied PageReference reference (from IPageSource).
Declaration
public virtual PageData GetPage(PageReference pageLink)
Parameters
Type | Name | Description |
---|---|---|
PageReference | pageLink |
Returns
Type | Description |
---|---|
PageData |
IsValue(String)
Determine if the named property exists and holds a non-null value.
Declaration
public virtual bool IsValue(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The name of the page property to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the property exists with a valid value. |
LoadDisplayTemplate(BlockData)
Resolves and instantiates the web or user control for the BlockData.
Declaration
public virtual Control LoadDisplayTemplate(BlockData blockData)
Parameters
Type | Name | Description |
---|---|---|
BlockData | blockData | The block data to populate the control with. |
Returns
Type | Description |
---|---|
System.Web.UI.Control |
RegisterClientScriptFile(String)
Helper method to register a client script file. If the method is called multiple times using the same key, only a single instance of the file is registered.
Declaration
public virtual void RegisterClientScriptFile(string rootRelativePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | rootRelativePath | The script file that should be referenced. |
Remarks
The relativePath will be used as the unique script key.
Translate(String)
Translate the key into a language specific text.
Declaration
protected virtual string Translate(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A simplified XPath expression. See Remarks below. |
Returns
Type | Description |
---|---|
System.String | A string with the translated text. |
Remarks
TranslateFallback(String, String)
Translate the key into a language specific text. Will return supplied fallback string if no match is found.
Declaration
protected virtual string TranslateFallback(string key, string fallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A simplified XPath expression. See Remarks below. |
System.String | fallback | The string to return if no match was found for key. |
Returns
Type | Description |
---|---|
System.String | A string with the translated text. |
Remarks
TranslateForScript(String)
Translate the key into a language-specific and script-safe text.
Declaration
protected virtual string TranslateForScript(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A simplified XPath expression. See Remarks below. |
Returns
Type | Description |
---|---|
System.String | A string with the translated text. |