0

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.

fharreau
  • 2,105
  • 1
  • 23
  • 46
user1447679
  • 3,076
  • 7
  • 32
  • 69
  • Duplicate of location found [here](https://stackoverflow.com/questions/39322405/asp-net-duplicate-ids-and-templated-control-is-there-a-more-elegant-way)? – jProg2015 Jul 21 '17 at 15:43
  • Looks like that was my original question. The problem is I'm allowing users to enter their markup in the templated control so I don't see how the answer would work. I really want to figure out the proper way to implement the ITemplate as a class. Thank you for pointing it out as I failed to respond which isn't great. I'll do that now. – user1447679 Jul 21 '17 at 17:10
  • In addition, a separation of templates is more precise for this particular question. . I'd be forever grateful for a working example. This has been an off and on battle for a year. – user1447679 Jul 21 '17 at 17:11

0 Answers0