title: Control inside EditItemTemplate will be available in Page_Load() only if
body: <p><br /></p>
  
  <p>On my page I’ve defined controls TextBox1, Label1 and GridView1. Inside GridView1 I’ve defined the following template:</p>
  
  <pre><code>           &lt;asp:TemplateField&gt;
  
                &lt;ItemTemplate&gt;
                  &lt;asp:LinkButton runat="server" Text="Edit" CommandName="Edit" ID="cmdEdit" /&gt;         
                &lt;/ItemTemplate&gt;
  
                &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox Text='&lt;%# Bind("Notes") %&gt;' runat="server" id="textBoxNotes" /&gt;
                  &lt;br /&gt;&lt;br /&gt;
                  &lt;asp:LinkButton runat="server" Text="Update" 
                   CommandName="Update" ID="cmdUpdate" /&gt; 
                  &lt;asp:LinkButton runat="server" Text="Cancel" 
                   CommandName="Cancel" ID="cmdCancel" /&gt;
                &lt;/EditItemTemplate&gt;
  
              &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>If user enters a text into textBoxNotes and clicks cmdUpdate button, then on postback this text will already be available when Page_Load() is called. </p>
  
  <p><br /></p>
  
  <p>Thus, if user, before clicking the update button cmdUpdate, also entered into TextBox1 a string “something”, then the following code will extract the text user entered into textBoxNotes</p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          if(TextBox1.Text=="text from Notes")
          Label1.Text =((TextBox)gridEmployees.Rows[0].Cells[0].FindControl("textBoxNotes")).Text;
      }
  </code></pre>
  
  <p><br /></p>
  
  <p>A) The following code should also extract the text user entered into textBoxNotes, but the moment I click cmdEdit button, I get “Object reference not set to an instance of an object.” exception</p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          if(IsPostBack)
          Label1.Text =((TextBox)gridEmployees.Rows[0].Cells[0].FindControl("textBoxNotes")).Text;
      }
  </code></pre>
  
  <p>Why do I get this exception? It appears as if textBoxNotes doesn’t exist. But why wouldn’t it exist?</p>
  
  <p><br /></p>
  
  <p>thanx</p>