在自定义用户控件ASP的嵌套标签 [英] ASP Nested Tags in a Custom User Control

查看:108
本文介绍了在自定义用户控件ASP的嵌套标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用自定义用户控件在C#中,我不知道是否有任何的例子在那里怎么写其中一个接受嵌套的标签。例如,当你创建一个ASP:直放站你可以添加一个嵌套的标签的ItemTemplate

I'm just getting started with Custom User Controls in c# and I'm wondering if there is any examples out there of how to write one which accepts nested tags. For example, when you create an "asp:repeater" you can add a nested tag for "itemtemplate".

任何帮助appeciated!

Any help appeciated!

干杯

推荐答案

我写了一个的这个博客帖子前一段时间。简单地说,如果你有一个控制,下面的标记:

I wrote a blog post about this some time ago. In brief, if you had a control with the following markup:

<Abc:CustomControlUno runat="server" ID="Control1">
    <Children>
        <Abc:Control1Child IntegerProperty="1" />
    </Children>
</Abc:CustomControlUno>

您就需要在控制code是大致相同的:

You'd need the code in the control to be along the lines of:

[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; }
}

这篇关于在自定义用户控件ASP的嵌套标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆