如何实现与作INamingContainer自定义的面板? [英] How to implement a custom panel with INamingContainer?

查看:96
本文介绍了如何实现与作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.

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

First this is my custom control, MyPanel...

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

和我尝试使用它像这样:

And I try using it like so:

<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:

  • Templated User Control: http://msdn.microsoft.com/en-us/library/36574bf6.aspx
  • Templated Server Control: 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.

这篇关于如何实现与作INamingContainer自定义的面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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