title: FindControl in DataList Edit Mode
body: <p>As a new .net/C# web begginner, I always get tripped up when I try to use FindControl. Blam -flat on my face. Here is my current FindControl problem:</p>
  
  <p>I have an .aspx page and Form, then ajax updatePanel, inside it there is my DataList (DataList1) that has an EditItemTemplate: that has the following:</p>
  
  <pre><code>&lt;EditItemTemplate&gt;
  &lt;asp:Label ID="thumbnailUploadLabel" runat="server" text="Upload a new thumbnail image:"/&gt;&lt;br /&gt;
  &lt;asp:FileUpload ID="thumbnailImageUpload" runat="server" /&gt;
  &lt;asp:Button ID="thunbnailImageUploadButton" runat="server" Text="Upload Now" OnClick="thumbnailUpload"/&gt;&lt;br /&gt;
  &lt;/EditItemTemplate&gt;
  </code></pre>
  
  <p>In my C# code behind I have the OnClick code for the fileUpload object:</p>
  
  <pre><code>        protected void thumbnailUpload(object s, EventArgs e)
  
      {
  
      if (thumbnailImageUpload.HasFile)
  
        {
  
        //get name of the file &amp; upload
  
            string imageName = thumbnailImageUpload.FileName;
  
            thumbnailImageUpload.SaveAs(MapPath("../../images/merch_sm/" + imageName));
  
            //let'em know that it worked (or didn't)
            thumbnailUploadLabel.Text = "Image " + imageName + "has been uploaded.";
           }
           else
           {
           thumbnailUploadLabel.Text = "Please choose a thumbnail image to upload.";
       }
  </code></pre>
  
  <p>So of course I'm getting "Object reference not set to an instance of an object" for the FileUpload and the Label. </p>
  
  <p>What is the correct syntax to find these controls, before dealing with them in the OnClick event?</p>
  
  <p>The only way Ive used FindControl is something like:</p>
  
  <p>label thumbnailUploadLabel = DataList1.FindControl("thumbnailUploadLabel") as Label;</p>
  
  <p>But of course this is throwing the "Object reference not set to an instance of an object" error. Any help is very much appreciated.</p>
  
  <p>(I've also seen the 'recursive' code out there that is supposed to make using FindControl easier. Ha! I'm so green at C# that I don't even know how to incorporate those into my project.)</p>
  
  <p>Thanks to all for taking a look at this.</p>