tags:

views:

47

answers:

1

i have this code -

<td id="td_h1" runat="server" style="background-image:url(images/img_new.jpg);vertical-align:top">
<div id="title_1" runat="server" class="caption" >This is New</div>
</td>

here's the problem - this is the code from the .master.aspx page. Some file access this master page from different folders, and some files from root. And the img_new is visible only from root files or files in folder. how do i make that image visible from everywhere?

A: 

You have two options.

  1. You can use an absolute path, like this: url(/BaseDir/images/img_new.jpg)
  2. You can call ResolveClientUrl, which will return the correct path, like this:

    url(<%=ResolveClientUrl("images/img_new.jpg")%>)

EDIT: ResolveClientUrl takes a relative URL, so it should not start with ~/. Try again without ~/.

SLaks
server.mappath ?? in aspx?
sinae
do i have to use url() or can i just use (image/...jpg) ??
sinae
You have to have `url`.
SLaks
<%= dont work in aspx.
sinae
`<%= ... %>` does work in ASPX files.
SLaks
i tried this -<td id="td_h1" runat="server" style="background-image:url(<%=ResolveClientUrl("~/images/img_new.jpg")%>)">Nothing happened
sinae
What HTML did it produce? Is your `images` folder directly in the application root?
SLaks