ASP.Net User Control Template Instantiation

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-03-30T16:10:01Z Indexed on 2010/03/30 16:13 UTC
Read the original article Hit count: 426

Filed under:
|
|

Hi,

I created a user control that has a template container.

<cc:SearchResultItem ID="SearchResultItem1" Customer='<%# ((Customer)(((RepeaterItem)Container).DataItem)) %>' runat="server">                                                
    <NameTemplate>
        <%# Container.Name %>
    </NameTemplate>
</cc:SearchResultItem> 

This is control is placed in a repeater which lists some customers. The customer is than bound to the user control. When the name template is instantiated in the container, the customer object is not yet available, but I need to access its name because it needs to get parsed before.

protected void Page_Init(object sender, EventArgs e)
{
    if (nameTemplate != null )
    {
        // customer is null here, it is avaiable only after Page_Init...
        NameContainer container = new NameContainer(customer.Id, Parse(customer.Name));
        nameTemplate.InstantiateIn(container);
        placeHolder.Controls.Add(container);
    }
}

Question: How can I access properties set for the user control BEFORE the template container is instantiated? Thanks in advance!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about .NET