是否可以在asp.net中的自定义控件中定义多个<template>区域?</template>

时间:2011-03-02 16:57:17

标签: asp.net custom-controls

我目前有:

<uc:MyControl ...>
<Template>
</Template>
</uc:Mycontrol>

我想

<uc:MyControl ...>
<FishBiscuit>
html
</FishBiscuit>
<FishBiscuit>
html
</FishBiscuit>
<FishBiscuit>
html
</FishBiscuit>
<FishBiscuit>
html
</FishBiscuit>
.
.
.

但是我不确定它是否可能,或者如果它是如何连接的话。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

使用您选择的方法似乎不太可能。下一个标记

<uc:MyControl runat="server">
    <FishBiscuit>
        html1
    </FishBiscuit>
    <FishBiscuit>
        html2
    </FishBiscuit>
</uc:MyControl>
如果您使用自定义控件的html2属性,则

应仅设置最后一个模板(public ITemplate FishBiscuit值)。所以,有两种方法:

  • 使用不同的属性作为 Brian说,

  • 或使用类似的控件 MultiView用于您的目的。

请参阅,您在上面发布的标记可以转换为:

<asp:MultiView runat="server">
    <asp:View runat="server">
        html
    </asp:View>
    <asp:View runat="server">
        html
    </asp:View>
    <asp:View runat="server">
        html
    </asp:View>
    <asp:View runat="server">
        html
    </asp:View>
</asp:MultiView>

更接近你提出的标记。

答案 1 :(得分:0)

它们必须是不同的属性:

[
PersistenceMode(PersistenceMode.InnerProperty),
TemplateInstance(TemplateInstance.Single)
]
public ITemplate FishBiscuit { get; set; }

[
PersistenceMode(PersistenceMode.InnerProperty),
TemplateInstance(TemplateInstance.Single)
]
public ITemplate FishBiscuit2 { get; set; }

上面定义的每个模板都会转换为属性,因此它必须具有匹配的属性名称。

HTH。

相关问题