[RESOLVED] [2005] ITemplates automatically instanciated at runtime??
I have a class inheriting from a (web) control.
It has 2 templates as below:
Code:
private ITemplate _DisplayTemplate = null;
private ITemplate _LoadingTemplate = null;
[TemplateContainer(typeof(DisplayContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DefaultValue(null)]
public ITemplate DisplayTemplate
{
get { return _DisplayTemplate; }
set { _DisplayTemplate = value; }
}
[TemplateContainer(typeof(DisplayContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DefaultValue(null)]
public ITemplate LoadingTemplate
{
get { return _LoadingTemplate; }
set { _LoadingTemplate = value; }
}
For reference here's the DisplayContainer and LoadingContainer, just empty classes:
Code:
public class DisplayContainer : Control, INamingContainer
{
}
public class LoadingContainer : Control, INamingContainer
{
}
Nowhere in the code do i instanciate these classes.
Dispite this, at runtime when i navigate to the page containing this control both templates display on the page (once set of controls for each template).
All examples i've seen have some sort of container control, then instanciate the templates in a runtime-created control and add them to that container control, but i've not even done that since i want to show different templates depending on different conditions.
Surely with no code to instanciate any templates there should be no markup shown for my new control (beyond maybe an empty div or something).
What am i missing?
Re: [2005] ITemplates automatically instanciated at runtime??
How are they placed on the page?
Re: [2005] ITemplates automatically instanciated at runtime??
Cheers for the reply.
Quote:
Originally Posted by mendhak
How are they placed on the page?
Code:
<hwc:DeferredLoading ID="DeferredLoading1" runat="server">
<DisplayTemplate>
<asp:SqlDataSource runat="server" ID="dsSQLDataSource1" SelectCommand="S...." ConnectionString="<%$ ..... %>"></asp:SqlDataSource>
<asp:GridView runat="server" ID="GridView1" DataSourceID="dsSQLDataSource1">
</asp:GridView>
</DisplayTemplate>
<LoadingTemplate>
Loading!
</LoadingTemplate>
</hwc:DeferredLoading>
Re: [2005] ITemplates automatically instanciated at runtime??
I haven't ventured much into this territory but from what I do know, I think you'll need to set the visibilities of those templates rather than Instantiate them. The TemplateContainer attribute is supposed to be the naming container rather than the 'HTML' container of your template, so it shouldn't make a difference if it's there or not. I might be wrong though but I'm half right half the time. Except when I'm not right.
Re: [2005] ITemplates automatically instanciated at runtime??
Cheers Mendhak! That did it. I didn't realise i had to instanciate both templates in the overloaded CreateChildControls method. Once i'd done that and made the container controls private members i could change their visibility accordingly.
Looks like you weren't not right this time.
Now, to make a designer for my new-fangled control!
Re: [RESOLVED] [2005] ITemplates automatically instanciated at runtime??
My only reaction is :eek2: no wai wow.