我刚刚开始使用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; } }
原文地址:https://www.jb51.cc/csharp/91719.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。