EPiWiki.se  - EPiServer notes shared with others
 

How to use PropertyControlClassFactory

[Edit]
An extremely easy sample how to use the PropertyControlClassFactory to render PropertyString different from the standard implementation.

OverridePropertyStringOutput.cs


This code is going to render all PropertyString to start with the text “Property string say:” <value>.

using System.Web.UI.WebControls;
using EPiServer.Web.PropertyControls;

namespace EPiServer.Templates
{
    public class OverridePropertyStringOutput : PropertyStringControl
    {
        public override void CreateDefaultControls()
        {
            Label output = new Label();
            output.Text = "Property string say:" + ToWebString();
            Controls.Add(output);
        }

        public override void CreateEditControls()
        {
            base.CreateEditControls();
        }
    }
}


global.asax.cs


The property conrol has to be replaced in Global.asax.

public override void Init()
{
    PropertyControlClassFactory.Instance.RegisterClass(
        typeof(PropertyString),
        typeof(OverridePropertyStringOutput));
}


Page.aspx



<EPiServer:Property PropertyName="PageName" runat="server" />


Will generate the output
Property string say:How to use PropertyControlClassFactory
Version author:
Mattias Lövström

EPiServer version

'EPiServer CMS 5'