如何使用 INamingContainer 实现自定义面板?自定义、如何使用、面板、INamingContainer

由网友(繼續赱紅 爷已看淡红尘╯)分享简介:我正在尝试实现一个可用作命名容器的自定义面板控件.到目前为止,这就是我所做的.I'm trying to implement a custom panel control that would act as a naming container. So far here is so what I've done.首...

我正在尝试实现一个可用作命名容器的自定义面板控件.到目前为止,这就是我所做的.

I'm trying to implement a custom panel control that would act as a naming container. So far here is so what I've done.

首先这是我的自定义控件,MyPanel...

First this is my custom control, MyPanel...

[ToolboxData("<{0}:MyPanel runat=server></{0}:MyPanel>")]
public class MyPanel: Panel, INamingContainer
{
}

我尝试像这样使用它:

<cc1:MyPanel ID="A" runat="server">
    <asp:HyperLink ID="TestHyperLink" runat="server" />
</cc1:MyPanel>
<cc1:MyPanel ID="B" runat="server">
    <asp:HyperLink ID="TestHyperLink" runat="server" />
</cc1:MyPanel>

显然它不起作用,那太容易了.ASP.net 仍然抱怨有 2 个 DocumentHyperLink:

Obviously it doesn't work, that would have been too easy. ASP.net still complains about there being 2 DocumentHyperLink:

The ID 'DocumentHyperLink' is already used by another control.

我应该如何解决这个问题?

How am I supposed to approach this problem?

谢谢.

推荐答案

听起来您可能会受益于模板化控件设计,而不是面板设计.以下是一些开始使用模板化控件的资源:

It sounds like you might benefit from a templated control design, instead of from a Panel design. Here are some resources to get started with templated controls:

模板化用户控制:http://msdn.microsoft.com/en-us/library/36574bf6.aspx模板化服务器控制:http://msdn.microsoft.com/en-us/library/aa478964.aspx

模板化设计的吸引力在于允许在另一个模板中重复服务器控件 ID.

The appeal of templated designs is that repeating a server control ID from one template in another is permitted.

阅读全文

相关推荐

最新文章