Background-image for TD tag with ASP.NET
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 accesses 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?
You have two options.
- You can use an absolute path, like this:
url(/BaseDir/images/img_new.jpg)
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 ~/
.
精彩评论