title: populating a text box with FindControl
body: <p>I have multiple textboxes and I want to programatically populate them with the same method.</p>
  
  <pre><code>&lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
      &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
      &lt;/asp:ScriptManager&gt;    
      &lt;asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="500"&gt;
          &lt;ProgressTemplate&gt;
              &lt;div id="FreezeUpdate" class="FreezePaneOn"&gt;
                 &lt;div id="InnerFreezePane" class="InnerFreezePane gradient"&gt;&lt;asp:Literal ID="litProgress" runat="server" Text="&lt;%$ Resources:LocalizedText, freezeMsg_ProcessingPleaseWait %&gt;"&gt;&lt;/asp:Literal&gt;&lt;/style&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/ProgressTemplate&gt;
      &lt;/asp:UpdateProgress&gt;
      &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
          &lt;asp:TextBox ID="tbxCollectionAddress" runat="server" TextMode="MultiLine" ReadOnly="True" CssClass="address"&gt;&lt;/asp:TextBox&gt;
          &lt;asp:TextBox ID="tbxReturnAddress" runat="server" TextMode="MultiLine" ReadOnly="True" CssClass="address"&gt;&lt;/asp:TextBox&gt;
      &lt;/asp:UpdatePanel&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>then the method...</p>
  
  <pre><code>protected void PopulateAddress(string txtTextbox, Address adrAddress)
      {
          TextBox txtAddress = (TextBox)FindControl(txtTextbox);
  
          txtAddress.Text = "Hello World";
  
      }
  </code></pre>
  
  <p>when I call this method like below...</p>
  
  <pre><code>PopulateAddress("tbxReturnAddress", CollectionAddress);
  </code></pre>
  
  <p>...I get exception...</p>
  
  <blockquote>
    <p>System.NullReferenceException: Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>...and it highlights the <code>txtAddress.Text = "Hello World";</code>  line.</p>
  
  <p>I'd like to do it like this with the method because there are three separate addresses that I need to populate on the form but I'd like to try using re-usable code to do it by feeding in the address object and the textbox id, but I'm falling over just at the findcontrol stage.</p>
  
  <p>What am I missing?</p>