Master page problem

X

xlar54

I have a very simple 2.0 website (framework), that uses a master
page...not. I added the default.aspx page as a webcontent form, with
the master page as it's master page, but the master page is never
displayed. Not sure whats wrong. Below is my code. Any help would
be appreciated. VS2008.

MasterPage1.Master:

<%@ Master Language="C#" AutoEventWireup="true"
CodeBehind="MasterPage1.master.cs"
Inherits="Register.WebApplication.MasterPage1" %>

<!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>Untitled Page</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">

<p>
This is the master page</p>

</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>


And default.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage1.Master"
AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="Register.WebApplication.Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<p>
This is default.aspx</p>
</asp:Content>
 
H

HillBilly

Type the Master in each content page (Default.aspx):

<%@ MasterType VirtualPath="~/MasterPage1.master" %>

Whatever HTML or text in ContentPlaceHolder1 as declared in MasterPage1 will
be over-ridden by the Content2 control in the Content Page.

I would also refer to the videos at asp.net that will give you code examples
to start with. Watching as many as possible helps as each usually covers a
separate MasterPage issue.
 
X

xlar54

But the odd thing is... I didnt write a single line of that code other
than the "this is the master page" and "this is default.aspx". The
rest came completely from the designer. Is Visual Studio doing
something wrong here?
 
H

HillBilly

Not VS2008 or any other tool will ever write all the code for all of the
circumstances we might encounter. I thought the Register.WebApplication
namespaces sounded wierd. Where do they come from?

But the odd thing is... I didnt write a single line of that code other
than the "this is the master page" and "this is default.aspx". The
rest came completely from the designer. Is Visual Studio doing
something wrong here?
 
J

Jeff Dillon

xlar54 said:
I have a very simple 2.0 website (framework), that uses a master
page...not. I added the default.aspx page as a webcontent form, with
the master page as it's master page, but the master page is never
displayed. Not sure whats wrong. Below is my code. Any help would
be appreciated. VS2008.

MasterPage1.Master:

<%@ Master Language="C#" AutoEventWireup="true"
CodeBehind="MasterPage1.master.cs"
Inherits="Register.WebApplication.MasterPage1" %>

<!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>Untitled Page</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">

<p>
This is the master page</p>

</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>


And default.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage1.Master"
AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="Register.WebApplication.Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<p>
This is default.aspx</p>
</asp:Content>

Also, what do you mean "the master page is never displayed". It won't
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top