Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.Net用户控件模板实例化_C#_.net_Asp.net - Fatal编程技术网

C# ASP.Net用户控件模板实例化

C# ASP.Net用户控件模板实例化,c#,.net,asp.net,C#,.net,Asp.net,我创建了一个具有模板容器的用户控件 <cc:SearchResultItem ID="SearchResultItem1" Customer='<%# ((Customer)(((RepeaterItem)Container).DataItem)) %>' runat="server"> <NameTemplate> <%# Conta

我创建了一个具有模板容器的用户控件

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

问题:在实例化模板容器之前,如何访问为用户控件设置的属性?提前谢谢

我认为你做不到。在对控件进行数据绑定之前,如何访问该控件的数据绑定属性


从您发布的代码来看,我并不认为在Init期间需要这样做,但我可能遗漏了一些东西。您能否澄清为什么在初始化期间而不是在加载或预渲染期间需要客户?

当在加载或预渲染时实例化模板时,模板不再工作。。。
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);
    }
}