1

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

4
  • 6
    Why place it in a ContentPLaceHolder at all? You can put the <link rel="stylesheet" in the head as is. Commented Jul 23, 2019 at 18:58
  • I agree with @VDWWD, removing your two ContentPlaceHolders from the Master page and just using the links in the head there would be easier and cleaner imo Commented Jul 23, 2019 at 19:01
  • And when putting the link in the head, try dragging the CSS file from Solution Explorer to the head tag. Commented Jul 23, 2019 at 19:04
  • Thanks, guys. This is the easiest solution I have found for this issue. please post that as an answer so I can upvote it :D Commented Jul 23, 2019 at 19:07

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.