ITemplate and inbedded controls

P

Perecli Manole

I created a tabstrip custom control that is declared like this:

<acc:TabStrip ID="Tabs" runat="server" SelectedTabID="aa"
AutoPostBack="true">
<Tab ID="aa" Text="aa">
<Template/>
</Tab>
<Tab ID="bb" Text="bb"/>
<Template>
<asp:panel ID="test" ..... or any other control />
</Template>
</Tab>
</acc:TabStrip>

I am using <ControlBuilder(GetType(TabStrip.ControlBuilder)),
ParseChildren(False)> attributes on the TabStrip Class and overrided
AddParsedSubObject() to add the Tabs to a collection of type
StateManagedCollection. Then somewhere in PreRender as I am iterating
through the collection I am doing this
"objTab.Template.InstantiateIn(objTableCell)" to place the contents of the
template in a TableCell that is being rendered by the TabStrip control.
Everything renderes and operates properly, however, as a control consumer, I
have not found a way to access any of the controls contained in the
template. In the example above I can not access the control with ID="test"
in the code behind so if I wanted to change any properties of these
controls, on post back, I could not. How should I change my implementation
to allow my consumers to access the controls contained in the <Template>
tags.

Perry
 
M

Milosz Skalecki

Hi Perceli,

I suspect you're trying to access controls that have not been created - this
is because you instantiate template on prerender, whilst it should be done
earlier (CreateChildControls + EnsureChildControls are designed for this), of
course to find the control in the template, you must call FindControl of the
control template is instantiated in, (CType(objTableCell.FindControl("test"),
Panel) in this case)

hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top