title: I don't really understand Page.FindControl
body: <p>I have an image like this:</p>
  
  <pre><code>&lt;asp:Image runat="server" ID="btnabout1" ImageUrl="~/graphics/buttons/btnabout1.png" AlternateText="About" /&gt;
  </code></pre>
  
  <p>I can access the control from code-behind like this (obviously):</p>
  
  <pre><code>btnabout1.Visible = false;
  </code></pre>
  
  <p>But this doesn't work:</p>
  
  <pre><code>Page.FindControl("btnabout1").Visible = false;
  </code></pre>
  
  <p>The point is to use a variable controlID and set attributes.</p>
  
  <p>I guess I am mis-understanding the method, so can someone enlighten me, please.</p>
  
  <hr>
  
  <p>The purpose is to create a method that takes the filename of the current page and sets images/buttons visible/invisible accordingly.  Like this:</p>
  
  <pre><code>string filename = System.IO.Path.GetFileName(HttpContext.Current.Request.FilePath);
  string strippedfilename = filename.Substring(0, filename.IndexOf("."));
  Page.FindControl("btn" + strippedfilename + "3").Visible = true;
  Page.FindControl("btn" + strippedfilename + "2").Visible = false;
  Page.FindControl("btn" + strippedfilename + "1").Visible = false;
  </code></pre>
  
  <p>Since I could't get Page.FindControl to work, I am using a </p>
  
  <pre><code>Dictionary&lt;string, Control[]&gt;
  </code></pre>
  
  <p>instead, but of course it's not as dynamic because adding new pages would mean having to add to the dictionary, but I guess it's ok for now...</p>