?
Solved

Master Page background image only visible from pages in root directory

Posted on 2006-05-23
9
Medium Priority
?
1,508 Views
Last Modified: 2008-01-09
I hope I can explain this well enough to understand.  I have a master page that is used by almost all of the pages in my site.  On the master page is a table.  In one of the cells in this table, I have set the background to display an image that is located in a directory called "images" which is just off the root directory.  Here's the problem:

Any page that is not located in the root directory (where the master page is located) cannot see the background image.  Pages that ARE located in the root directory can.  I have tried using "~/images/filename.jpg" for the background source but this didn't work.  In fact, the only that has worked so far is to put the full URL ("http://www.mysite.com/images/filename.jpg") for the background source.  I'm still relatively new to ASP.NET 2.0 and I don't know what (if any) problems using the full URL might cause.

Can anyone suggest a solution (or is using the full URL for this the correct way to go).

Thanks!
0
Comment
Question by:penlandt
  • 4
  • 3
  • 2
9 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 16745159
Don't put the full URL!

In your example of the full url, it does not contain your application (unless your application is named "images").  If this images folder can be guaranteed to be at the root no matter where the document might lie, Might I suggest using "/images/filename.jpg"
0
 
LVL 1

Author Comment

by:penlandt
ID: 16746792
Well...I'm not feeling very smart at the moment.  I've searched through all of the books I'm using to learn ASP.NET 2.0 and none of them has Application Name in the index.  Can you elaborate on this or perhaps point me to a resource that explains what this is, where it happens, and how to access it?  I'm increasing the point value of this question to reflect the added complexity.  Thanks again!
0
 
LVL 7

Expert Comment

by:skiltz
ID: 16747460
make sure you use the runat="server" command.

eg <img src="~/images/filename.jpg" runat="server">

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:penlandt
ID: 16748823
Thanks skiltz...but this is a cell background - doesn't use <img src="">   It uses <td background="~/images/filename.jpg"></td>

I did try adding runat="server" to the <td> tag and the <table> tag but it didn't help.  
0
 
LVL 7

Expert Comment

by:skiltz
ID: 16749058
try this.  if you already have a css file then don't create a new one.

in the msterpage (master.master or whatever you have called it)

Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        Dim link As HtmlLink = New HtmlLink()
   
        'this will be from the root so we are good now.
        link.Href = "~/css/images.css"
        link.Attributes.Add("rel", "stylesheet")
        link.Attributes.Add("type", "text/css")
        Page.Header.Controls.Add(link)

    End Sub


' css file images.css

.bgimage
{
    background-image: url(../images/filename.jpg);
  }

<td class="bgimage" runat="server">
0
 
LVL 33

Expert Comment

by:raterus
ID: 16751393
Here are a few articles on handling relative paths,

http://west-wind.com/weblog/posts/269.aspx
http://www.awprofessional.com/articles/article.asp?p=101145&rl=1

There was a really good article once on handling relative paths, but it seems to have gone dead and I can't find another link other than google's cached version?
http://72.14.209.104/search?q=cache:XJcop1vWyFMJ:www.dotnetdashboard.com/DesktopDefault.aspx%3Ftabindex%3D3%26tabid%3D64+Bustamante++relative+paths&hl=en&gl=us&ct=clnk&cd=1
0
 
LVL 1

Author Comment

by:penlandt
ID: 16826840
I've read a bit more on this subject and tried the following solution.  Problem is the background image doesn't appear at all now and I can't figure out why.  All the other stylesheet elements work (I've tested this by changing fonts and sizes).  Any idea what I'm doing wrong?  Thanks:

-----------------------------------------
Web.config
-----------------------------------------
<system.web>
    <pages theme="Default"></>
</system.web>
-----------------------------------------
Stylesheet.css
-----------------------------------------
.mpagetopctr
{
    font-family: Verdana;
    font-size: medium;
    background-image: url(App_Themes/Default/Images/Borders/lefttopcurve_red.jpg);
}
-----------------------------------------
Masterpage.master
-----------------------------------------
<table>
  <tr>
     <td class="mpagetopctr" runat="server">
          Header Text
     </td>
  <tr>
<table>

0
 
LVL 33

Accepted Solution

by:
raterus earned 2000 total points
ID: 16833929
Just look at that stylesheet, it looks like you are using a relative url for the background-image, I'd put a "/" in front of it

.mpagetopctr
{
    font-family: Verdana;
    font-size: medium;
    background-image: url(/App_Themes/Default/Images/Borders/lefttopcurve_red.jpg);
}
0
 
LVL 1

Author Comment

by:penlandt
ID: 16834118
Odd...I didn't notice before but the Style Builder in WebDev Express 2005 left off the "/" at the beginning of the url.  You're right...that fixed it.  Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question