title: How to programmatically access a control on a aspx page from the cs file
body: <p>How can I access a control on an aspx page from the cs file in a programmatic way?</p>
  <p>For instance, if I have a set of asp:Panel controls each with an ID named by a city (id=&quot;atlanta&quot;, id=&quot;chicago&quot;, id=&quot;pittsburgh&quot;, etc.) and then in the cs I grab a value from the database to match up to the control names what would I use?</p>
  <p>I tried to use FindControl() as shown and it returns null.</p>
  <p>aspx page:</p>
  <pre><code>&lt;asp:Panel ID=&quot;atlanta&quot; runat=&quot;server&quot; Visible=&quot;false&quot;&gt;&lt;/asp:Panel&gt;
  </code></pre>
  <p>cs file:</p>
  <pre><code>controlName = storeLocation.City.ToLower();
  Panel cityPanel = (Panel)FindControl(controlName);
  cityPanel.Visible = true;
  </code></pre>
  <p>I suppose FindControl() is really for use in cases like Repeaters or Grids where you pass in the ItemTemaplate.  In my case its just a simple content page with a content tag with a bunch of panels in it.</p>