Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5243
  • Last Modified:

Master page error

Hello,

I am getting this error "The page contains markup that is not valid when attached to a master page" whe I am adding a master page. My master page cod is-
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="hp_lab.master.cs" Inherits="***" %>

<!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></title>
   
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
   
</head>
<body>
    <form id="form1" runat="server">
     <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/hp.jpg"
         Width="1067px" /><br />

    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
 
        </asp:ContentPlaceHolder>
    </div>
    </form>
    <p>
        &nbsp;</p>
</body>
</html>

What is that I am doing wrong?
Thanks,
0
armbsu
Asked:
armbsu
  • 20
  • 6
  • 2
1 Solution
 
silemoneCommented:
i think it has to do with other pages...makes sure other pages that use this masterpage do not have

<!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></title>
   
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
   
</head>
<body>
in them...
0
 
silemoneCommented:
oops...i see the error


remove this from title


 <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
0
 
silemoneCommented:
all aspnet controls must be in a form with like:    <form id=form1 runat=server>

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Anurag ThakurTechnical ManagerCommented:
because you cannot add a contentplaceholder in the head section
remove this and it should work fine
<asp:contentplaceholder id="head" runat="server">
</asp:contentplaceholder>
0
 
silemoneCommented:
so disregard my first post,

remove this from underneath the title tag...


 <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
0
 
silemoneCommented:
if you wish to add script, or other data to <head part of page, you must do it in code behind using Page.Title, etc...
0
 
armbsuAuthor Commented:
did that, ragi017, did not help,

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="hp_lab.master.cs" Inherits="****" %>

<!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></title>      
</head>
<body>
    <form id="form1" runat="server">
     <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/hp.jpg"
         Width="1067px" /><br />
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">          
        </asp:ContentPlaceHolder>
    </div>
    </form>
    <p>
        &nbsp;</p>
</body>
</html>
0
 
silemoneCommented:
i told you to remove that first...so what error are you getting now?
0
 
silemoneCommented:
Inherits="****"     here is another error....remove that please...
0
 
silemoneCommented:
replace with:

Inherits="hp_lab.master"
0
 
armbsuAuthor Commented:
Silemone,  
I am still getting the same error, but one thing I noticed though when I changed something, how do I refresh that, There is no button to refresh, and any change in master page does not refresh in other aspx pages.
0
 
Anurag ThakurTechnical ManagerCommented:
at least my code compiles now
i have just removed the imageurl
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Test.master.cs" Inherits="Test" %>
<!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">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
		<asp:Image ID="Image1" runat="server" ImageUrl="" Width="1067px" /><br />
		<div>
			<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
			</asp:ContentPlaceHolder>
		</div>
	</form>
	<p>
		&nbsp;</p>
</body>
</html>

Open in new window

0
 
silemoneCommented:
how are you running program when you test it?  I'll copy what you should have so far:
if you're running this from Vs2005/etc...then you just run the program and it should update...
What environment are you using to program in?


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

<!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></title>      
</head>
<body>
    <form id="form1" runat="server">
     <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/hp.jpg"
         Width="1067px" /><br />
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">          
        </asp:ContentPlaceHolder>
    </div>
    </form>
    <p>
        &nbsp;</p>
</body>
</html>
0
 
silemoneCommented:
This one should definitely have cleaned up all syntax errors...

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

<!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></title>      
</head>
<body>
    <form id="form1" runat="server">
     <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/hp.jpg"
         Width="1067px" /><br />
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">          
        </asp:ContentPlaceHolder>
    </div>
    </form>
    <p>
        &nbsp;</p>
</body>
</html>
0
 
armbsuAuthor Commented:
silemone:,

I am using VS2008 VWD.  strill getting the same error
What I am doing is-
1. I have created a master page, as explained.
2. In my Login.aspx, I am saying that  MasterPageFile="~/hp_lab.master" , but after including this line, what I am geeting is -Content is not supported outside'script ; or asp.net content region,  when I hover the mouse on html. word (<html xmlns="http://www.w3.org/1999/xhtml" >) on login.aspx page

This is so simple stuff, sorry I am not able to understand.
0
 
silemoneCommented:
pls refer to my first post...

better yet post your login page...pls...

remember any pages that utilize a masterpage will not have <body>, etc...<html>  because those are already included in the masterpage...


0
 
armbsuAuthor Commented:
This is my login.aspx.


<%@ Page Language="C#" MasterPageFile="~/hp_lab.master"  AutoEventWireup="true" CodeBehind="login.aspx.cs"  Inherits="working_with_bal_files.fall_risk.login"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
/*this html is causing the error statement****
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <style type="text/css">
        #form1
        {
            width: 855px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <p>
&nbsp;</p>
    <p>
                nbsp;
    </p>
    <p style="margin-left: 320px">
        <br />
        <asp:Login ID="Login1" runat="server" BackColor="#EFF3FB" BorderColor="#B5C7DE"
            BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
            Font-Size="Medium" ForeColor="#333333" Height="105px"
            onauthenticate="Login1_Authenticate1" Width="335px">
            <TextBoxStyle Font-Size="0.8em" />
            <LoginButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
            <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
            <TitleTextStyle BackColor="#507CD1" Font-Bold="True" Font-Size="0.9em"
                ForeColor="White" />
        </asp:Login>
        <br />
&nbsp;&nbsp;&nbsp;
    </p>
    <p style="margin-left: 320px">
    <asp:Label ID="Label3" runat="server" Text="Create a new account"
            BorderColor="#EFF3FB" Font-Bold="True" Font-Size="Medium"></asp:Label>
    </p>
    <p style="margin-left: 320px">
        <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="Please enter the User Name"></asp:RequiredFieldValidator>
    </p>
    <p style="margin-left: 320px">
        <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
        ControlToValidate="TextBox2" ErrorMessage="Please enter the password"></asp:RequiredFieldValidator>
    </p>
    <p style="margin-left: 320px">
&nbsp;<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="Create new account" />
    </p>
    <p>
        <asp:Label ID="lblResults" runat="server"></asp:Label>
    </p>
    <p>
        <asp:Label ID="lblTryAginUserName" runat="server"></asp:Label>
    </p>
    <p>
nbsp;
    </p>
    </form>
</body>
</html>

I see that I should not have html and body when dealing with master pages, so how do I do it without body and html?
0
 
silemoneCommented:
again...refer to my first post...you can't have
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <style type="text/css">
        #form1
        {
            width: 855px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">  in your page if it refers to a masterpage, because

1) you can only have one form with runat=server in your page...
2) all this is already contained in the masterpage and that's the purpose of the masterpage...
3) the script is allowed in login page...
0
 
silemoneCommented:

<%@ Page Language="C#" MasterPageFile="~/hp_lab.master"  AutoEventWireup="true" CodeBehind="login.aspx.cs"  Inherits="working_with_bal_files.fall_risk.login"  %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 
    <style type="text/css">
        #form1
        {
            width: 855px;
        }
    </style>
    <p>
&nbsp;</p>
    <p>
                nbsp;
    </p>
    <p style="margin-left: 320px">
        <br />
        <asp:Login ID="Login1" runat="server" BackColor="#EFF3FB" BorderColor="#B5C7DE"
            BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
            Font-Size="Medium" ForeColor="#333333" Height="105px"
            onauthenticate="Login1_Authenticate1" Width="335px">
            <TextBoxStyle Font-Size="0.8em" />
            <LoginButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
            <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
            <TitleTextStyle BackColor="#507CD1" Font-Bold="True" Font-Size="0.9em"
                ForeColor="White" />
        </asp:Login>
        <br />
&nbsp;&nbsp;&nbsp;
    </p>
    <p style="margin-left: 320px">
    <asp:Label ID="Label3" runat="server" Text="Create a new account"
            BorderColor="#EFF3FB" Font-Bold="True" Font-Size="Medium"></asp:Label>
    </p>
    <p style="margin-left: 320px">
        <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="Please enter the User Name"></asp:RequiredFieldValidator>
    </p>
    <p style="margin-left: 320px">
        <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
        ControlToValidate="TextBox2" ErrorMessage="Please enter the password"></asp:RequiredFieldValidator>
    </p>
    <p style="margin-left: 320px">
&nbsp;<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="Create new account" />
    </p>
    <p>
        <asp:Label ID="lblResults" runat="server"></asp:Label>
    </p>
    <p>
        <asp:Label ID="lblTryAginUserName" runat="server"></asp:Label>
    </p>
    <p>
nbsp;
    </p>
   </asp:Content>

Open in new window

0
 
armbsuAuthor Commented:
worked!!
0
 
silemoneCommented:
so here's what I suggest  you do:

since you have a masterpage,  add a new Item -->select a new form...name it and MAKE SURE checkbox 'Select Master Page' is checked...then you will be taken to a little window and highlight your masterpage...


from there take the content that is inside the <form tag of your login.aspx page and place it in the <asp:Content of new page...

and don't forget to take the script you have in the login and place at the very top...within <script type="text/javascript"></script> tags
0
 
silemoneCommented:
oops..not script, but styles you have...
0
 
silemoneCommented:
then why did you give me a B grade?
0
 
silemoneCommented:
:0)..but thanks for the points...

cheers...
0
 
armbsuAuthor Commented:
silemone,
Since these master pages started working my other programs are failing.  In my forms I have calendar control.  Before using a master page, calendar contorl would pick a date and put  it textbox2, but now it's throwing error.
vs-error.jpg
0
 
silemoneCommented:
ok...i'll look over...
0
 
silemoneCommented:
ok...i see the problem...Once you added the Masterpage, the master page added this:  cl00$to the front of your variables...


so here goes:

use this:

document.getElementById("<%= textBox.ClientID%>").value = "11/12/2008";
0
 
silemoneCommented:
document.getElementById("<%= TextBox6.ClientID%>").value = "11/12/2008";
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 20
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now