Set default value on a custom property
I have created a longstring custom property that gives me a XHTML editor. So far so good but I need help with two things.
First, I would like to fill the property with a default value. I've looked at a couple of blog post about this but can't seem to get it right.
Second, I would want to render the custom property as a regular textbox
that can hold a large string.
public class CustomerTypeBoxControl :
EPiServer.Web.PropertyControls.PropertyLongStringControl
{
protected override void SetupEditControls()
{
base.SetupEditControls();
}
public CustomerTypeBox CustomerTypeBox
{
get
{
return PropertyData as CustomerTypeBox;
}
}
}
[Serializable]
[PageDefinitionTypePlugIn]
public class CustomerTypeBox : EPiServer.Core.PropertyLongString
{
public override IPropertyControl CreatePro开发者_Go百科pertyControl()
{
return new CustomerTypeBoxControl();
}
}
Don't know if it is steel relevant but here is the solution:
TextBox _textBox;
protected override void SetupEditControls()
{
base.SetupEditControls();
_textBox = (TextBox)EditControl;
var value = CustomerTypeBox.Value ?? string.Empty;
if (String.IsNullOrEmpty(value.ToString()))
{
_textBox.Text = "Default text";
}
else
{
_textBox.Text = value.ToString();
}
if (_textBox != null) EditControl.Parent.Controls.Add(_textBox);
}
public override void ApplyEditChanges()
{
var customerTypeBoxValue = _textBox.Text;
if (customerTypeBoxValue != null)
{
SetValue(customerTypeBoxValue);
}
}
Default value for property is also possible to set in admin mode.
精彩评论