Matt Wilko
Matt Wilko

Reputation: 27342

Child Page Doesn't Pick Up Styles From Master

I can't get my child page to pick up styles defined in my master. Here is what I did:

This shows up with a red background fine in the designer

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

Answers (2)

Russell Walters
Russell Walters

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

user710031
user710031

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

Related Questions