我试图用“嵌套”属性实现自定义复合WebControl,即将一组属性封装到类中。作为对象的ASP.NET自定义WebControl嵌套属性
例如,在这个复合控件中,我放置了一个按钮。我希望能够将按钮的相关属性封装到类中(例如,buttonText,buttonStyle等)。这将使得多按钮/控件组合控件中的定义属性更加容易且一致且直观。
注:我想封装的属性出现在VisualStudio中的属性对话框中,以与Style/Font非常相似的方式分组。
样品:
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
}
不幸的是,这种做法DOS无法正常工作。新属性myButtonProperties完全不出现在“Properies”对话框中。