ITemplate container will not render.

Discussion in 'ASP .Net Building Controls' started by cmartinbot, Feb 12, 2007.

  1. cmartinbot

    cmartinbot Guest

    Hello and TIA.

    I have a very simple server control that has one property that needs
    to be rendered in an ITemplate. I can't seem to figure out why it
    won't render with the <%# Container.Value%> syntax inside the
    declarative template.

    The container control for the template is being instantiated

    It should be said that this control lives within a Repeater
    ItemTemplate which I suspect is the reason for this not working.

    Relative Code:

    public class CustomData : WebControl, INamingContainer
    private ITemplate content;
    private string currentValue;

    protected override void CreateChildControls()
    if( !ChildControlsCreated )
    IDataRetriever retriever = DataRetriever.Create(dataType, article,
    forceFetch, label);

    currentValue = retriever.ValueString;


    ChildControlsCreated = true;

    private void InstantiateTemplate(ITemplate template)
    if(template == null)
    template = new DefaultTemplate( currentValue );

    DataContainer container = new DataContainer(currentValue);
    Controls.Add( container );

    #region Properties

    [PersistenceMode( PersistenceMode.InnerProperty )]
    public ITemplate Content
    get { return content; }
    set { content = value; }


    public class DataContainer : Control, INamingContainer
    private string value;

    public DataContainer(string value)
    this.value = value;

    public string Value
    get { return value; }
    set { this.value = value; }

    <cc1:CustomData ID="CustomData2" DataType="ShortString" runat="server"
    <Content>(CityIsHereButNotShowing[<%# Container.Value%>])</Content>

    Please help!!!

    Thanks again,
    Chris Martin
    cmartinbot, Feb 12, 2007
    1. Advertisements

  2. cmartinbot

    Teemu Keiski Guest

    Have you overridden DataBind method to recreate child controls?

    Something like:

    public override void DataBind()
    ChildControlsCreated = false;
    ChildControlsCreated = true;


    You don't also need to check ChildControlsCreated in CreateChildControls,
    calling EnsureChildControls will do that. And in CreateChildControls the
    first line should be Controls.Clear();
    Teemu Keiski, Feb 14, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.