<foo:TabMenu runat="server"><Tabs><Tab Label="Tab1" PanelID="pnlTab1"/><Tab Label="Tab2" PanelID="pnlTab2"/><Tab Label="Tab3" PanelID="pnlTab3"/></Tabs></foo:TabMenu>解决方法 你需要这样的东西.一切都很好,但你必须完成TabCollection类.
编辑:原谅我,我没有测试代码.无论如何发现一些问题所以解决了他们.
用户控件
[ParseChildren(true,"Tabs"),PersistChildren(false)]public partial class TabMenu : UserControl{ private TabCollection _tabs; [browsable(false),PersistenceMode(PersistenceMode.InnerProperty),MergableProperty(false)] public virtual TabCollection Tabs { get { if (this._tabs == null) this._tabs = new TabCollection(this); return this._tabs; } } protected overrIDe ControlCollection CreateControlCollection() { return new TabMenuControlCollection(this); }}
标签
public class Tab : HTMLGenericControl{ public string Label { get { return (string)VIEwState["Label"] ?? string.Empty; } set { VIEwState["Label"] = value; } }}
TabCollection
public class TabCollection : IList,ICollection,IEnumerable{ private TabMenu _tabMenu; public TabCollection(TabMenu tabMenu) { if (tabMenu == null) throw new ArgumentNullException("tabMenu"); this._tabMenu = tabMenu; } public virtual int Add(Tab tab) { if (tab == null) throw new ArgumentNullException("tab"); this._tabMenu.Controls.Add(tab); return this._tabMenu.Controls.Count - 1; } int IList.Add(object value) { return this.Add((Tab)value); } // You have to write other methods and propertIEs as Add.}
TabMenuControlCollection
public class TabMenuControlCollection : ControlCollection{ public TabMenuControlCollection(TabMenu owner) : base(owner) { } public overrIDe voID Add(Control child) { if (child == null) throw new ArgumentNullException("child"); if (!(child is TabMenu)) throw new ArgumentException("The TabMenu control can only have a child of type 'Tab'."); base.Add(child); } public overrIDe voID AddAt(int index,Control child) { if (child == null) throw new ArgumentNullException("child"); if (!(child is TabMenu)) throw new ArgumentException("The TabMenu control can only have a child of type 'Tab'."); base.AddAt(index,child); }}总结
以上是内存溢出为你收集整理的c# – ASP.NET:构建以列表作为参数的用户控件?全部内容,希望文章能够帮你解决c# – ASP.NET:构建以列表作为参数的用户控件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)