Can't find controls in FormView.InsertItemTemplate even on DataBound event

Posted by abatishchev on Stack Overflow See other posts from Stack Overflow or by abatishchev
Published on 2010-04-23T16:15:52Z Indexed on 2010/04/23 16:43 UTC
Read the original article Hit count: 563

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET