Masterpage issue with relative links to background images

S

Steve Franks

I am familiar with the fact that you have to use runat=server and links
staring with "~/" to ensure proper mapping of paths to relative URLs when
using master pages. However this does not seem to work in all cases.

For instance, assume I have a "/mysite/images" subdirectory with
mybackground.gif and mygif.gif in there.

Further assume I have a master page called mastertest.aspx located in
/mysite/myfolder".

In mastertest.aspx this works to produce a proper link to an image:
<img src="~/images/mygif.gif" width="10" height="18" runat=server>

However, this DOES NOT work:
<table width="100" background="~/images/mybackground.gif" runat=server>

For some reason the runat=server works to translate links properly when its
an IMG SRC tag, but not when its a BACKGROUND attribute in a table tag. Why
is this?

What is the work around for this situation? I need to be able to have
ASP.NET dynamically generate the proper relative links to my background
images that are used by my html tables via the BACKGROUND attribute.

Please let me know what I am doing wrong and how I can fix this.

Thanks!

Steve
 
C

clintonG

Understanding the 'new but not really new' control and event processing
model [1] is helpful followed up by review of the web application root
operator [2] rules. Check out this forum post [3] regarding usage.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://msdn2.microsoft.com/library/dct97kc3(en-us,vs.80).aspx
[2] http://msdn2.microsoft.com/library/ms178116(en-us,vs.80).aspx
[3] http://forums.asp.net/941135/ShowPost.aspx
 
J

Juan T. Llibre

re:
I have a master page called mastertest.aspx

You can't.

You may have a master page called mastertest.master,
not one called mastertest.aspx

Then, you could have any page display the master
page's content by including this line in the aspx page :

<%@ Page Language="VB" MasterPageFile="~/Mastertest.master" %>

You *still* have to use the tilde ( ~ ) as a reference to the
application's root directory, if you want relative paths to work.

See : http://beta.asp.net/QUICKSTART/aspnet/doc/masterpages/default.aspx
for a tutorial on how to use master pages.



Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
===========================
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top