【发布时间】:2011-03-04 01:53:00
【问题描述】:
一些 ASP.NET 控件只允许某些类型的项目,例如:
<uc:MyControl runat="server"....>
<MyTableTemplate>
<MyTableRow .... />
<MyTableRow .... />
<MyTableRow .... />
</MyTableTemplate>
</uc:MyControl>
我正在尝试在我自己的自定义控件中重新创建它,这样您就只能将 MyTableRow 对象放入模板中,而 Visual Studio 将阻止设计者放入其他任何东西。
我一直在查看 ControlBuilder 课程,但我不能完全确定它是否符合我的要求。此外,示例没有提到我上面的嵌套,其中 MyTableRow 的数组位于另一个模板字段中。
有谁知道如何做到这一点?
编辑:UpdatePanel 似乎是这样工作的:如果您这样声明 UpdatePanel:
<asp:UpdatePanel>
<Triggers>
</Triggers>
</asp:UpdatePanel>
除了 intellisense 中列出的两个特定控件之外,您不能在 Triggers 部分中放置任何内容,如果您尝试,则会收到设计时错误。这正是我想要模仿的行为。
====
我尝试执行 Alex 的建议,这是我的代码:
public partial class MyControl : System.Web.UI.UserControl
{
[PersistenceMode(PersistenceMode.InnerProperty)]
public ActionButtonCollection ActionButtons
{
get;
set;
}
}
public class ActionButtonCollection : Collection<ActionButton>
{
}
public abstract class ActionButtonBase
{
public string Test { get; set; }
}
public class ActionButton : ActionButtonBase
{
}
然而,这段代码里面没有智能感知
<uc:MyCustomControl runat="server">
<ActionButtons>
</ActionButtons>
</uc:MyCustomControl >
【问题讨论】: