Setting virtual path on Table controls

  • Thread starter Thread starter Nick
  • Start date Start date
N

Nick

Hi,

I have some simple html:

<table>
<tr>
<td background="~/images/category_background.jpg" runat=server></td>
</tr>
</table>

If I hardcode the path for the background, all is fine, but using the tilde
and runat server doesnt work. I need to work with relative paths, because
the HTML is in a web usercontrol shown on pages at different levels.

Any advice?

Nick.
 
Try to use the following expression:

<table>
<tr>
<td
background='<%=ResolveUrl("../images/category_background.jpg")%>'></td>
</tr>
</table>

So, you can use relative paths. But don't forget to use ' instead of " in
background='' propert, overwise ASP.NET shows an syntax error.

Gaidar
 
Gaidar,

Thanks for replying. I have tried your advice, which seems sound, but when
I view the HTML in the browser, I see:

<td
background="<%=ResolveUrl(&quot;../images/promos/simplePromo_shade_leftside.jpg&quot;);%>">
</td>

The C# isnt being compiled and executed....any thoughts?

Thanks

Nick.
 
I got it working Gaidar.

One further question is how performant is it to keep using ResolveUrl for
all urls on the page? Is it not a problem because the page gets compiled
anyway? I have put a script block at the top of my control, and access the
base image URL using ResolveUrl. I then access this field in my code:

<table>
<tr>
<td
background='<%=Path + "categoryMenu_background.jpg"%>'></td>
</tr>
</table>

Thanks

Nick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top