Why could I be unable to apply style on a nested page which is using a master page? I am just trying to apply simple some back-color to body and some div in an individual page.
My (nested)page Reservations.aspx has this code
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeFile="Reservations.aspx.cs" Inherits="Reservations" %>
<asp:Content runat="server" ContentPlaceHolderID="HeadContent">
<link href="~/Styles/input.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div class="mainDiv">
........
</div></asp:Content>
input.cs has this code
body { background-color:Silver; }
.mainDiv { background-color:Blue; }
Site.Master has this code
<head runat="server">
<asp:ContentPlaceHolder ID="HeadContent" runat="server"></asp:ContentPlaceHolder>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" /></head>
<body>.........
I can get Silver Color as background of Reservations.aspx only if I apply this to master page which I do not want. I have not been able to get helped from accepted answer of This question and tutorials.
Edit
using <link.. before or after might make some difference, thanks for info but it is not doing anything in this case. I have tested it both ways after my problem was solved.
Guidance to ResolveUrl solved my problem, because I tried using pickurl in visual-studio 2010 instead of typing manually and got this url Styles/input.css instead of ~/Styles/input.css.
Update => How it was Solved
href="Styles/Site.css" or href='<%= ResolveUrl("~/Styles/Site.css")%>'
You need to use resolve url as follows.
as follows
Working when your
Master PageandContent Pageare on the same folder then any include in the master page will work.But when your
Master PageandContent Pageare in different folder it will not find the same style sheet or java-script file because files are not in the same folder.So Resolve Url resolve the URL on the server.