Hello ASP.NET community,
I recently a control that is very simple, really. It's suppose to look like the UpdatePanel
<asp:UpdatePanel>
<ContentTemplate>
Stuff
</ContentTemplate>
</asp:UpdatePanel>
as you know where i have "stuff" we can put all bunch of controls and then initialise them in the code behind.
In my control I do the same,
private ITemplate tmpContentTemplate = null;
[DefaultValue(null)]
[Description("The content template.")]
[TemplateContainer(typeof(ContentTemplateContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateInstanceAttribute(TemplateInstance.Single)]
public ITemplate ContentTemplate
{
get { return tmpContentTemplate; }
set { tmpContentTemplate = value; }
}
Notice that my ContentTemplate is TemplateInstance.Single so it's not bound anywhere and that means that all the stuff in it are accessible to the page, so for example if I do
<my:CustomControl>
<ContentTemplate>
<my:OtherControl ID="x" runat="server" />
</ContentTemplate>
</my:CustomControl>
then I would like to be able to do something like
x.Text = "hello";
In the code behind.
In UpdatePanel this works fine the stuff within the template are never null but in my control they are always null, even though I'm exposing the ContentTemplate to the page, so I'm wondering what I'm doing wrong.
I thought maybe I should be calling EnsureChildControls somewhere.. not sure what I'm doing wrong.
Any ideas??
Thank you very much in advance