CSS rendering issue after logout - asp.net

I have one main masterpage and three that inherit from it; my site changes masterpages based on the state of the user (logged out, logged in without admin privileges, logged in with admin privileges) in order to change the side menu appropriately.
When I'm logged in, the master pages normaluser.master and admin.master work just fine.
When I'm logged out, loggedout.master fails to render any css from the stylesheet, turning my pretty side menu into a list of underlined blue links and removing all header styles.
MasterPage.master:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-color: rgb(231, 231, 255);height:100%;margin:0px;padding:0px">
<form id="form1" runat="server">
<div style="background-color:rgb(74, 60, 140);color: rgb(247, 247, 247);height:20%">
<div style='width:7%;display:inline-block;border:none;padding:0px;padding-left:2px'>
<img src="Images/globe2.png" style="height:100px;vertical-align:middle"/>
</div>
<div style='display:inline-block;vertical-align:middle;'>
<span style='font-size:36pt;padding-left:10px;font-family:Century,inherit'> Welcome To MeetSmart: </span><span style="font-size:16pt;font-style:italic"> Your smarter meeting solution</span>
</div>
</div>
<div style="height:80%">
<div style='width:15%;height:100%;display:inline-block;text-align:center;margin-top:10px;padding:0px;'>
<asp:ContentPlaceHolder id="Menu" runat="server">
</asp:ContentPlaceHolder>
</div>
<div style='display:inline-block;margin:0px;padding-left:10px;padding-top:20px;border:2px solid purple;width:75%;height:100%;vertical-align:top'>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</form>
</body>
</html>
normaluser.master:
<%# Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="normaluser.master.cs" Inherits="normaluser" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>
<asp:ContentPlaceHolder id="title" runat="server">
</asp:ContentPlaceHolder>
</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" Runat="Server">
<div class='menuItem'> <a href="Schedule.aspx" class='menuItem'>My Schedule </a></div>
<div class='menuItem'> <a href="MyProfile.aspx" class='menuItem'>My Profile </a></div>
<div class='menuItem'> <a href="DocManagerUser.aspx" class='menuItem'>Document Center </a></div>
<div class='menuItem'> <a href="Directory.aspx" class='menuItem'>Directory</a></div>
<div class='menuItem'> <a href="Logout.aspx" class='menuItem'>Log out </a></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ContentPlaceHolder id="mainContent" runat="server">
</asp:ContentPlaceHolder>
</asp:Content>
loggedout.master:
<%# Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="LoggedOut.master.cs" Inherits="LoggedOut" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link runat="server" href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>
<asp:ContentPlaceHolder id="title" runat="server">
</asp:ContentPlaceHolder>
</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" Runat="Server">
<div class='menuItem'><a href="Login.aspx" class='menuItem'>Log In </a><br /></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ContentPlaceHolder id="mainContent" runat="server">
</asp:ContentPlaceHolder>
</asp:Content>
With or without "runat=server", the stylesheet link in loggedout does nothing; adding that was one way I tried to solve it. All the master pages and the stylesheet are in the same folder.

Considering your descriptions, looks like your CSS is in a directory which is secured under authentication. In order to have the CSS and scripts to be available on Login and other un-authenticated pages, you would need to make them available beyond authentication.
To do this, you can add those CSS and scripts etc, to a directory (say Public folder on root) and use location element in web.config to provide access to everyone to these directoy. This has not compromise on your security as such.
<configuration>
<location path="Public">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>

Related

Master page content not showing up in child

I know there is something I am missing on this
But am unable to figure out that
I have this master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Mains.master.cs" Inherits="Sportsstop.Mains" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sports Stop</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
N there is this Child page which should merge with the above master page:
<%# Page Title="" Language="C#" MasterPageFile="~/Mains.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Sportsstop.Home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server" >
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
Your textbox should be in child page, inside ContentPlaceholder1. I think that the one in master page is ignored.
If you want to have TextBox in master page, it cannot be inside ContentPlaceholder
Think about placeholder as a place, where the content from child page gets injected

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:
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"
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.
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.

Does disabling viewstate in a page do anything if it has a masterpage with it enabled?

I have a page that uses a master page.
I disabled viewstate on the page (not the master page), and I didn't notice that the viewstate was reduced.
Curious if the masterpage setting will override it?
In my testing setting EnabledViewState = "False" will not reduce the page's view state while setting ViewStateMode="Disabled" will decrease the viewstate size
Master Page
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="ViewStateTest.master.cs" Inherits="Sample.ViewStateTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
Child Page
<%# Page Title="" Language="C#" MasterPageFile="~/ViewStateTest.master" AutoEventWireup="true" CodeBehind="ViewstateTestPage.aspx.cs" Inherits="Sample.ViewstateTestPage" ViewStateMode="Disabled" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:TextBox runat="server"></asp:TextBox>
</asp:Content>

js and css defined in the masterpage does not included in the child page

Hi:
I am new to asp.net,so I meet some problem about the master page.
I define a master page and set some css and js within it:
<%# Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" >
<title>Master page title</title>
<script xx.js></script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td><asp:contentplaceholder id="Main" runat="server" /></td>
<td><asp:contentplaceholder id="Footer" runat="server" /></td>
</tr>
</table>
</form>
</body>
</html>
Then my child page:
<% # Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
Footer content.
</asp:content>
When I start the child page,I found the xx.js is not included in this page,what is the problem?
<head>
<script type="text/javascript" src="xx.js"></script>
</head>
This "xx.js" should be in your appl

Master Pages using Side Panels

I have used Master Pages with ASP.Net for some time. I have been able to develop Master pages with header and footing content but never sucessful with side panels.
What this project needs is a Main Master page with header and footer contents. Then another master page that uses the first master page and has it's content of the left side of the remaining middle. The Detail will go to the right with the left master content about one third and the detail about two third.
A working example would be good if possible.
Thanks.
Bob
Possibly looking for nested master pages?
Site.master
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="MySite.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</form>
</body>
Nested.master
<%# Master Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Nester.master.cs" Inherits="MySite.NestedMaster" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div style="float:left;width:200px;margin-right:5px;">
<asp:ContentPlaceHolder runat="server" ID="LeftNavigation"></asp:ContentPlaceHolder>
</div>
<div style="float:left;width:440px;margin-right:5px;>
<asp:ContentPlaceHolder runat="server" ID="MainContents"></asp:ContentPlaceHolder>
</div>
<div style="clear:both;"></div>
</asp:Content>
Default.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Nested.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MySite.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="LeftNavigation" runat="server">
<p>Left navigation content</p>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContents" runat="server">
<p>Body content</p>
</asp:Content>

Resources