How can I get a class that implements ITemplate to allow duplicate IDs?

435 Views Asked by At

This works:

Public Class HelloWorld
  Inherits CompositeControl
  Implements INamingContainer

  <PersistenceMode(PersistenceMode.InnerProperty)>
  Public Property TemplateA() As ITemplate

  <PersistenceMode(PersistenceMode.InnerProperty)>
  Public Property TemplateB() As ITemplate

End Class

And:

<me:HelloWorld>
  <TemplateA>
    <me:SomeControl>
      <asp:Textbox Id="Bob" />
    </me:SomeControl>
  </TemplateA>
  <TemplateB>
    <me:SomeControl>
      <asp:Textbox Id="Bob" />
    </me:SomeControl>
  </TemplateB>
</me:HelloWorld>

But what I'd rather do, is implement ITemplate in a class so I can also use custom properties and other things:

Public Class TemplateA
  Inherits TemplateBase
  Implements INamingContainer, ITemplate

  ... Properties

  Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
      container.Controls.Add(Me)
  End Sub
End Class

But then I get a duplicate ID error for the Textbox. Can someone please show me an example of this? I've read through countless templated control tutorials and found examples of people doing this, but apparently it isn't implementing the Itemplate in the same way. Examples in C# or VB.net are fine.

0

There are 0 best solutions below