Reputation: 27342
I can't get my child page to pick up styles defined in my master. Here is what I did:
I created a stylesheet Main.css
in the root of my app
body {
background-color:red;
}
I created a Master Page Site.Master
in the root of my web application
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb" Inherits="WebApplication1.Site" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
<link href="Main.css" rel="stylesheet" />
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
Master Page`
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
This shows up with a red background fine in the designer
I created a child page WebForm.aspx
in the root of my app
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
Child Page Contents
</asp:Content>
But this doesn't show a red background either in the designer or at runtime. When I view source there is no css declaration in the file, yet it is picking up the master page because it displays "Master Page
Child Page Contents
"
Upvotes: 0
Views: 1870
Reputation: 86
Replace this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
<link href="Main.css" rel="stylesheet" />
</asp:ContentPlaceHolder>
with
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="Main.css" rel="stylesheet" />
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
The link to your css sheet is inside a content place holder.
Upvotes: 0
Reputation:
Restructure your Master Page to look like this:
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<link href="Main.css" rel="stylesheet" type="text/css" />
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
Master Page`
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
You need to link the stylesheet in the head tag, not the ContentPlaceHolder one.
Upvotes: 1