tags:

views:

71

answers:

1

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!

A: 

I don't think you can. How could you access a databound property of the control before the control is databound?

From the code that you've posted, I don't actually see a need to do this during Init, but I'm probably missing something. Can you clarify why you need the customer during Init and not during Load or PreRender?

womp
When instanstiate the template at Load or PreRender the template is not working anymore...
Chris