title: How to use asp:image in code behind
body: <p>I have a problem with rendering asp:image in code behind.
  First I explain my method:
  In <code>Default.aspx</code> I just use one label.
  In code behind I make a string variable and fill it, then I fill the <code>lable.Text</code> by my string variable.<br>
  this is my <code>Default.aspx</code>:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="test_Default2" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form id="form1" runat="server"&gt;
     &lt;div&gt;
        &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
     &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is my form load function in Defaul.aspx.cs:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      Label1.Text = @"&lt;asp:Image ID='Image1' runat='server'   ImageUrl='~/images/sc/tiraje.jpg' /&gt;
                      &lt;br/&gt;
                      &lt;img src='../images/sc/tiraje.jpg' /&gt;
                      ";
  }
  </code></pre>
  
  <p>Now this code must render two images. But first image used by asp:image doesn't work! I need to use asp:image in my string variable because my URL changes my result, for example if my URL is:</p>
  
  <pre><code>http://localhost:19551/website/test/Default.aspx
  </code></pre>
  
  <p>When I give it one "/":</p>
  
  <pre><code>http://localhost:19551/website/test/Default.aspx/ 
  </code></pre>
  
  <p>The second URL causes to change the src of second image in my string that I use in <code>&lt;img&gt;</code> tag. so that I want to use asp:image because it uses "~/" for src (imageUrl) that never changes by change URL!</p>