How to give path for image in a master page for two sub-pages in two locations?

3.9k Views Asked by At

Hi all my work environment is asp.net c# vs2008. My issue is this, i have a master page outside.master in shared folder.Inside it i have an image control with

<img src="App_Themes/Home/images/logo.png" />

i am referring this master page from in two sub pages. One is Index.aspx which is located in the root level and Secondly registration.aspx which is under masters folder. The problem is that when i run, the index.aspx will show the logo where registration.aspx is not showing the logo. Please tell me how to specify the path so that i will get logo in both pages.

3

There are 3 best solutions below

0
On BEST ANSWER

Tilde sign ~ will resolve for server side controls.

So you need to add runat="server" as img in HTML element.

Try this:

<img src="~/App_Themes/Home/images/logo.png" runat="server"/>
2
On

Try the following:

<img src="~/App_Themes/Home/images/logo.png" runat="server" />
0
On

The most foolproof method is to have something like this

<asp:Image runat="server" id="myImage" ImageUrl='<%# Eval("imageFile") %>' />

Then in the code-behind assign the variable imageFile to something like Server.MapPath("App_Themes/Home/images/logo.png");