[英]Set default value on a custom property
我创建了一个longstring自定义属性,该属性为我提供了XHTML编辑器。 到目前为止,还不错,但是我需要两点帮助。
首先,我想用默认值填充属性。 我看过几篇关于此的博客文章,但似乎做得不好。
其次,我想将自定义属性呈现为可以容纳大字符串的常规textbox
。
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 CreatePropertyControl()
{
return new CustomerTypeBoxControl();
}
}
不知道它是否与钢铁相关,但是以下是解决方案:
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);
}
}
属性的默认值也可以在管理模式下设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.