c# – 自定义用户控件中的ASP嵌套标记
发布时间:2020-12-15 04:24:39 所属栏目:百科 来源:网络整理
导读:我刚刚开始使用c#中的自定义用户控件,我想知道是否有任何关于如何编写接受嵌套标签的示例.例如,当您创建“asp:repeater”时,可以为“itemtemplate”添加嵌套标记. 有任何帮助! 干杯 解决方法 不久前我写了一篇关于这个的 blog post.简而言之,如果您有一个
我刚刚开始使用c#中的自定义用户控件,我想知道是否有任何关于如何编写接受嵌套标签的示例.例如,当您创建“asp:repeater”时,可以为“itemtemplate”添加嵌套标记.
有任何帮助! 干杯 解决方法
不久前我写了一篇关于这个的
blog post.简而言之,如果您有一个带有以下标记的控件:
<Abc:CustomControlUno runat="server" ID="Control1"> <Children> <Abc:Control1Child IntegerProperty="1" /> </Children> </Abc:CustomControlUno> 您需要控件中的代码遵循以下方式: [ParseChildren(true)] [PersistChildren(true)] [ToolboxData("<{0}:CustomControlUno runat=server></{0}:CustomControlUno>")] public class CustomControlUno : WebControl,INamingContainer { private Control1ChildrenCollection _children; [PersistenceMode(PersistenceMode.InnerProperty)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Control1ChildrenCollection Children { get { if (_children == null) { _children = new Control1ChildrenCollection(); } return _children; } } } public class Control1ChildrenCollection : List<Control1Child> { } public class Control1Child { public int IntegerProperty { get; set; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |