title: Setting imageURL using a function in ASP.NET
body: <p>I've done this task before within repeaters and it has worked.  However I can't get the below to work for me in a normal webforms page.  The images appear as broken links and breakpoints I put in the codebehind are not triggered.</p>
  
  <p>(in the aspx file)</p>
  
  <pre><code>&lt;asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='&lt;%# GetImageDirectory()%&gt;btnRunReport.png'  /&gt;
  </code></pre>
  
  <p>(codebehind)</p>
  
  <pre><code>public string GetImageDirectory()
  {
      return "~/App_Variants/LBSX/images/";
  }
  </code></pre>
  
  <p>This is the second method I've tried, in the other one I tried passing the imagename through as a string, and it would return the entire link that way.  Still no luck!</p>
  
  <p>Any thoughts?</p>
  
  <p>Thanks!</p>
  
  <p>[EDIT] Thanks for the help everyone.  In the end after the handy hints I found a recursive snippet which did the trick as follows:</p>
  
  <pre><code>private void UpdateImages(Control Parent)
  {
      foreach (Control c in Parent.Controls)
      {
          ImageButton i = c as ImageButton;
          if (i != null)
          {
              i.ImageUrl = "~/App_Variants/LBSX/images/" + i.ImageUrl;
          }
          if (c.HasControls())
          {
              UpdateImages(c);
          }
      }
  }
  
  protected void Page_Load(object sender, EventArgs e)
  {
      UpdateImages(Page);
      ...
  </code></pre>
  
  <p>Hope it helps someone else.</p>
  
  <p>Cheers</p>