5

I have a tag in a master page. I use this master page in many folders. So the src path of the tag should be different for each folder. Here is my code :

<img src="images/1.gif" />

and I have a folder named "images" and a folder named "Users". Master Page is in the root, but I use it in Users folder.

How can I set a dynamic address for src?

Mehdi Dehghani
  • 77
  • 1
  • 1
  • 3

2 Answers2

13

The easiest way would be to use an asp:Image tag. You need to add runat="server" in order to use ~ syntax to resolve your URLs.

<asp:Image ID="myImage" runat="server" ImageUrl="~/images/1.gif" />
Matt Hidinger
  • 1,743
  • 16
  • 16
6

Just use <img runat="server" src="~/images/1.gif" />. This is documented here.

RichardOD
  • 28,883
  • 9
  • 61
  • 81