md1337
md1337

Reputation: 1450

How to implement a custom panel with 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.

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>

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.

Upvotes: 1

Views: 2210

Answers (1)

kbrimington
kbrimington

Reputation: 25642

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:

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

Upvotes: 3

Related Questions