Search code examples
c#htmlcssasp.netmaster-pages

asp.net master page css not applying to asp form pages


I am new to asp.net programming and have come into this unusual error. I have a master page called Master.Master which contains the following code for specifying a CSS file.

<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>

    <asp:ContentPlaceHolder ID="Stylesheets" runat="server">
        <link rel="stylesheet" href="~/Styles/StyleSheet.css" type="text/css" />
    </asp:ContentPlaceHolder>
</head>

note that for the master page the CSS works perfectly with no issues, I have since created a default asp web form which takes all contents from the Master.Master page. This page however is not displaying the CSS at all, here is that pages code.

<%@ Page Title="Home" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="GarageManager.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="stylesheets" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

from researching this issue many users on here even suggested using script language for resolving URL like such, but to no avail.

<a runat="server" href="<%= this.ResolveUrl(~/Styles/StyleSheet.css) %>" onmouseover="document.Home_Img.src='<%= this.ResolveUrl("Images/home_2.png") %>'"
        onmouseout="document.Home_Img.src='<%= this.ResolveUrl("Images/home.png") %>'">
        <img alt="" src="Images/home.png" name="Home_Img" runat="server" />
    </a>

thanks in advance


Solution

  • Just get rid of the head and stylesheets ContentPlaceHolders and do this in your Master.Master file:

    <head>
        <link rel="stylesheet" href="~/Styles/StyleSheet.css" type="text/css" />
    </head>