开发者

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.

  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 ~/.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜