I have a default1.master page that contains a background image and menu bar site map. I created a new page and specified the use of the master page during it's creation.
It looks good. I created another new page, and I specified the master page during it's creation but only the menu bar displays, the background image does not???
The image path is basing on its host page. If we use "background="Images/CommonBG.jpg"" in the subfolder, this path expects the Image folder under this subfolder.
To work around it, we can use "~/" to point to root folder and convert it to right path. For example:
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
I put your suggestion in the html where I thought it might go. Below is the code from the master page. When I go to run, I get errors stating 'imgpath' is not declared .
I am using VB (not sure if that would change your code or not). I also tried defining imgpath like Public imgPath as String = ...... that did not work either.
From your code above, we need to declare that variable in the server code instead of client code, and the example I posted above is using C#.
In your case, we can declare that variable in codebehind class I.E. "Default1.master.vb":
Partial Class MasterPage
Inherits System.Web.UI.MasterPage Public imgPath As String = System.Web.VirtualPathUtility.ToAbsolute("~/Images/CommonBG.jpg")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Thanks.
Thomas Sun
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Marked as answer by StrangerMike on Jun 23, 2010 03:51 PM
StrangerMike
Contributor
2705 Points
1721 Posts
Master page background image
Jan 13, 2009 02:56 PM|LINK
I have a default1.master page that contains a background image and menu bar site map. I created a new page and specified the use of the master page during it's creation.
It looks good. I created another new page, and I specified the master page during it's creation but only the menu bar displays, the background image does not???
Any ideas?
StrangerMike
Contributor
2705 Points
1721 Posts
Re: Master page background image
Jan 13, 2009 03:09 PM|LINK
Here is another clue, that may help you help me.
If a new web page sits on the root of the application, it appears to use the background image.
However, If I create the web page inside a folder on the root, it seems this is when the background image does not display. Does this make sense?
StrangerMike
Contributor
2705 Points
1721 Posts
Re: Master page background image
Jan 13, 2009 03:52 PM|LINK
I found some others who had the same problem. I'm trying to work through fixes but I still can't get the BG image to display on a page in a subfolder.
Currently the image is assigned like this: (displays image on master page, but not on pages in sub folder)
background
="../MySite/Images/CommonBG.jpg"If I assign like this I don't even get an image on the masterpage:
background
="/MySite/Images/CommonBG.jpg"This produces an image on the background page, but not on the pages in a sub folder:
background="Images/CommonBG.jpg"Can you assist. Thanks
Thomas Sun –...
All-Star
64969 Points
5621 Posts
Re: Master page background image
Jan 16, 2009 06:45 AM|LINK
Hi,
The image path is basing on its host page. If we use "background="Images/CommonBG.jpg"" in the subfolder, this path expects the Image folder under this subfolder.
To work around it, we can use "~/" to point to root folder and convert it to right path. For example:
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
public string imgPath = System.Web.VirtualPathUtility.ToAbsolute("~/Images/CommonBG.jpg");
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="background-image: url('<%= imgPath %>')">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
Content Page
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
I look forward to receiving your test results.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
StrangerMike
Contributor
2705 Points
1721 Posts
Re: Master page background image
Jan 16, 2009 07:05 PM|LINK
Thank you Thomas,
I put your suggestion in the html where I thought it might go. Below is the code from the master page. When I go to run, I get errors stating 'imgpath' is not declared .
I am using VB (not sure if that would change your code or not). I also tried defining imgpath like Public imgPath as String = ...... that did not work either.
Any ideas?
%@ Master Language="VB" CodeFile="Default1.master.vb" Inherits="Default1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> protected void Page_Load(object sender, EventArgs e) { } public string imgPath = System.Web.VirtualPathUtility.ToAbsolute("~/Images/CommonBG.jpg"); </script> </head> <body style="background-position:center 3%; background-repeat:no-repeat; "> <form id="form1" runat="server"> <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" /> <div style="background-image: url(' <%= imgPath %>')"> <div id="Header"></div> <div id="space" style="height:70px"></div> <div align=center id="Menu"> <asp:Menu ID="Menu1" style="text-align:Left" runat="server" DataSourceID="SiteMapDataSource1" BackColor="#FFFFCC" DynamicHorizontalOffset="2" Font-Names="Arial" Font-Size="14px" ForeColor="Purple" Orientation="Horizontal" StaticDisplayLevels="2" StaticSubMenuIndent="13px" Width="888px"> <StaticSelectedStyle BackColor="#FFCC66" /> <StaticMenuItemStyle HorizontalPadding="8px" VerticalPadding="2px" /> <DynamicHoverStyle BackColor="#990000" ForeColor="White" /> <DynamicMenuStyle BackColor="#FFFBD6" /> <DynamicSelectedStyle BackColor="#FFCC66" /> <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /> <StaticHoverStyle BackColor="#990000" ForeColor="White" /> </asp:Menu> </div> <div align=center id="content"> <table align=center> <tr> <td style="width: 262px"> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder> </td> </tr> </table> </div> </div> </form> </body> </html>Thomas Sun –...
All-Star
64969 Points
5621 Posts
Re: Master page background image
Jan 19, 2009 01:07 AM|LINK
Hi,
Thanks for your response.
From your code above, we need to declare that variable in the server code instead of client code, and the example I posted above is using C#.
In your case, we can declare that variable in codebehind class I.E. "Default1.master.vb":
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Public imgPath As String = System.Web.VirtualPathUtility.ToAbsolute("~/Images/CommonBG.jpg")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Thanks.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
fayaz_3e
Star
9332 Points
1744 Posts
Re: Master page background image
Apr 02, 2009 09:20 AM|LINK
Thank you Thomas. It helped me too.
atif.iu
Member
2 Points
1 Post
Re: Master page background image
Aug 11, 2009 03:01 AM|LINK
it works,,,,i hve tried lot of tricks earlier.....but none of them works...
thanks
romah
Member
29 Points
18 Posts
Re: Master page background image
Dec 11, 2009 01:56 PM|LINK
Thomas,
Thank you very much for your nice answer.
I was looking for this solution since last couple of days.
Romah
alextvino
Member
273 Points
94 Posts
Re: Master page background image
Jun 02, 2010 05:20 AM|LINK
Helped me too thanks gurus
Please: Don't forget to click "Mark as Answer" on the post that helped you.
Psalm 23 : 1-2
1 The LORD is my shepherd, I shall not be in want.
2 He makes me lie down in green pastures,he leads me beside quiet waters.