A whery simple code to create your own EPiServer CMS property.
MyProperty.cs
The property to store the property in
using EPiServer.Core;
using EPiServer.PlugIn;
namespace EPiServer.Templates
{
[PageDefinitionTypePlugIn(
DisplayName = "My Property",
Description = "",
SortIndex = 1)]
public class MyProperty : PropertyString
{
public override object Value
{
get { return base.Value; }
set { base.Value = value; }
}
}
}
MyPropertyControl.cs
The user interface to the property.
using System;
using EPiServer.Web.PropertyControls;
using System.Web.UI.WebControls;
namespace EPiServer.Templates
{
public class MyPropertyControl : PropertyStringControl
{
TextBox _inputControl;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_inputControl = new TextBox();
_inputControl.Text =
((string)PropertyData.Value) ?? String.Empty;
}
public override void CreateEditControls()
{
Controls.Add(_inputControl);
}
public override void ApplyEditChanges()
{
if (!String.IsNullOrEmpty(_inputControl.Text))
{
SetValue(_inputControl.Text);
}
}
}
}