Dailycode.info

Short solution for short problems

Image url in Masterpages

Everytime I start a new webproject I have to Google for a solution to the image path problem in masterpages. When you use a path in the masterpage and it is relative, it won't work in subdirectories. This solution works everytime for me:

<img id="ctlHeader_LogoImage" src='<%= ResolveUrl("~/imgs/logo.gif") %>'
 alt="test" style="border-width:0px;height:37px;width:133px;" />

 

The "resolve url" command can also be used for other paths, like stylesheets, links, etc...

I hope by posting this code, it will stay in my puny brain once and for all time!