views:

634

answers:

3

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?

+4  A: 

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- same end result as my way, but a few more changes.
RichardOD
Thanks.It's OK for <img> but another problem is for background-image attribute in <td> tag. like this :<td style="background-image: images/1.gif;"> </td>How can I solve it?
Mehdi Dehghani
style="background-image: url(<%= ResolveUrl("~/images/1.gif") %>);"
meandmycode
+3  A: 

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

RichardOD
A: 

What about for script tags?

Never mind.. Found the answer and posted it here:

http://stackoverflow.com/questions/1634449/relative-urls-in-sharepoint-master-page/3898034#3898034

Included examples for both and ... Worked with MOSS 2007.

Paul T.