Can't find controls in FormView.InsertItemTemplate even on DataBound event
- by abatishchev
I have FormView in my page markup:
<asp:FormView ruanat="server" ID="FormView1" OnDataBound="FormView1_DataBound" DataSourceID="SqlDataSource1">
<InsertItemTemplate>
<uc:UserControl1 runat="server" ID="ucUserControl1" />
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" SelectCommand="EXEC someSP" />
It's code-behind:
protected void FormView1_DataBound (object sender, EventArgs e)
{
var c1 = ((FormView)sender).FindControl("ucUserControl1"); // returns null
var c2 = FormView1.FindControl("ucUserControl1"); // also returns null
}
In theory, I'm able to find control on FormView after it being data bound. But I'm not. Why?