开发者

How to implement a custom panel with INamingContainer?

开发者 https://www.devze.com 2023-01-15 14:41 出处:网络
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.

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=开发者_JS百科"B" runat="server">
    <asp:HyperLink ID="TestHyperLink" runat="server" />
</cc1:MyPanel>

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?

Thank you.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消