title: Accesing controls of a FormView, getting Null references
body: <p>I have a FormView and I need to access some Divs and other controls that are inside it. My apsx code looks similar to this:</p>
  
  <pre><code> &lt;asp:FormView ID="Edit_FV" runat="server" DataKeyNames="IDproceso" DefaultMode="Edit" DataSourceID="SqlDS_Procesos"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;div id="second_info" runat="server"&gt;
                      &lt;div id="second_info_left" runat="server"&gt;
                          &lt;div id="alcance" class="report_field" runat="server"&gt;
                              &lt;p class="container-title"&gt;
                                  Alcance:&lt;/p&gt;
                              &lt;asp:TextBox ID="TextBox14" runat="server" TextMode="multiline" Width="400px" Height="120px" Text='&lt;%# Bind("alcance") %&gt;' /&gt;
                          &lt;/div&gt; 
                      &lt;/div&gt;
                      &lt;div id="second_info_right" runat="server"&gt;
                      &lt;div class="valores-container" id="tipo_ahorro" runat="server"&gt;
                          &lt;asp:CheckBox ID="ahorro_state" runat="server" Checked='&lt;%# Bind("tipo_ahorro") %&gt;'  /&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/EditItemTemplate&gt;
          &lt;/asp:FormView&gt;
  </code></pre>
  
  <p>Now, say I want to access the <code>CheckBox</code> with <code>id = ahorro_state</code>, I tried with <code>Edit_FV.FindControl("ahorro_state")</code> and got a Null reference. I also tried with <code>Edit_FV.FindControl("MainContent_Edit_FV_ahorro_state")</code> because this is how the ID actually gets named in the final HTML document, but I got a Null reference too. The same happened when I tried accessing any of the divs (with IDs <code>second_info</code>,<code>tipo_ahorro</code>, etc..). I feel I'm doing a dumb mistake but I looked around a bit and haven't found and answer. </p>
  
  <p>Any ideas how to solve this?</p>
  
  <p>EDIT: Added Code where I'm calling FindControl.</p>
  
  <p>I tried both calling DataBind() from the Page_Load():</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
  
              DataBind();
              if (Edit_FV.CurrentMode == FormViewMode.Edit)
              {
                  Control c = Edit_FV.FindControl("ahorro_state");//c is null here.
              }
          }
  </code></pre>
  
  <p>And also tried setting the OnDataBound attribute of Edit_FV: <code>OnDataBound="onBound"</code></p>
  
  <pre><code>   protected void onBound(object sender, EventArgs e)
              {
                  if (Edit_FV.CurrentMode == FormViewMode.Edit)
                  {
                      ControlCollection a = Edit_FV.Controls;
                      Control c = Edit_FV.FindControl("ahorro_state");//c is null here
                  }
  
              }
  </code></pre>