Accessing Child Controls of a Template Server Control

I've created a templated control that has a property called ContentTemplate which is of type ITemplate.  The control works great with the exception of I now have to interact with the child controls via the FindControl method.

Markup: 

<test:MyControl ID="testControl" runat="server">
  <ContentTemplate>
    <asp:Label ID="testLabel" runat="server" />
  </ContentTemplate>
</test:MyControl> 
 

 In order to interact with the child label, testLabel, I now need to do something like this:

Dim lbl As Label = CType(testControl.FindControl("testLabel"), Label)
lbl.Text = "Something new!"

Is there a way to avoid this?  The reason I think this is even possible is that the UpdatePanel of AJAX has a ContentTemplate property that still allows a developer to interact with the objects they create within that tag.

 Thanks!

0
Malhiec
2/4/2008 7:43:41 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

0 Replies
602 Views

Similar Articles

[PageSpeed] 33

Reply: