【发布时间】:2015-03-18 20:51:32
【问题描述】:
我正在尝试使用“嵌套”属性实现自定义复合 WebControl,即将一组属性封装到一个类中。
例如,在这个复合控件中,我放置了一个按钮。我希望能够将按钮的相关属性封装到一个类中(例如,buttonText、buttonStyle 等)。这将使在多按钮/控件复合控件中定义属性更容易、一致和直观。
注意:我希望封装的属性以与样式/字体非常相似的方式分组显示在 VisualStudio 的“属性”对话框中。
示例:
public class fooButtonProperties
{
[Category("Appearance"), Description("URL for the Profile page")]
public string URL { get; set; }
[Category("Appearance"), Description("Text to display"), DefaultValue("Profile")]
public string ButtonText { get; set; }
/// <summary>
/// Position of the control on the page, default is Right-Aligned
/// </summary>
[Category("Appearance"), Description("Position in the Header"), DefaultValue(PIONEERFramework.Web.UI.WebControls.PageHeaderFooter.Classes.DesignEnum.DesignLayoutEnums.HorizontalPositions.Right)]
///Here is the composite control
public PIONEERFramework.Web.UI.WebControls.PageHeaderFooter.Classes.DesignEnum.DesignLayoutEnums.HorizontalPositions PositionInHeader { get; set; }
}
public class myCustomClass: System.Web.UI.WebControls.CompositeControl
{
protected System.Web.UI.HtmlControls.HtmlLink myButton;
[Category("Appearance")]
public fooButtonProperties myButtonProperties { get { return _profileButtonProp; } }
private fooButtonProperties _myeButtonProp;
#region Constructor
public myCustomClass()
{
this._myeButtonProp = new fooButtonProperties ();
}
#endregion
}
不幸的是,这种方法不起作用。新属性 myButtonProperties 根本不会出现在“属性”对话框中。
【问题讨论】:
标签: c# asp.net web-controls