0

I have added a masterpage to my project, and now when i try to inherit this masterpage to one page, I get this error:

'Content controls have to be top-level controls in a content page or a nested master page that references a master page.'

master_page.Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="master_page.master.cs"Inherits="KitchenCounter.master_pages.MasterPage"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title> 
        <asp:Content runat="server" ContentPlaceHolderID="MainContent">
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
        </asp:Content>
</head>
<body>
    <asp:Content runat="server" ContentPlaceHolderID="MainContent">
        <asp:ContentPlaceHolder ID="MainContent" runat="server">
            <div class="menuBar">
                <ul>
                    <li class="hvr-bounce-to-bottom active"><a>Home</a></li>
                    <li class="hvr-bounce-to-bottom"><a href="../account/account.aspx">Account</a></li>
                    <li class="hvr-bounce-to-bottom"><a href="../recipes/recipes.aspx">Recipes</a></li>
                    <li class="hvr-bounce-to-bottom"><a href="../contact/contact.aspx">Contact</a></li>
                </ul>
            </div>
        </asp:ContentPlaceHolder>
    </asp:Content>
</body>
</html>

Index.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="KitchenCounter.pages.Index"  MasterPageFile="~/kitchencounter/master_pages/master_page.Master"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Kitchen Counter | Home</title>
    <link rel="stylesheet" href="kitchencounter/css/main.css" />
</head>
<body>

</body>
</html>

Any ideas where to start with this? Any help is appreciated.

Nizac
  • 3
  • 5

1 Answers1

0

The idea behind a master page with content pages is that your master page contains items that should appear on every (or most) page in your site, with placeholders left where a content page will fill in information specific to that page. With that premise in mind, there are a few things to change:

  1. You put the content controls in the master page; they need to go in the content page, which in your case is Index.aspx.
  2. Additionally, your content page should only contain as its top-level controls tags - you use the ContentPlaceHolderId attribute to match the content inside the tags on your content page to the places where the content belongs on the Master page.
  3. Finally, your markup for your navigation bar needs to be outside of the control on your Master page. The control is just that - a placeholder; nothing goes inside of it.

    So try this:

master_page.Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="master_page.master.cs"Inherits="KitchenCounter.master_pages.MasterPage"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <div class="menuBar">
            <ul>
                <li class="hvr-bounce-to-bottom active"><a>Home</a></li>
                <li class="hvr-bounce-to-bottom"><a href="../account/account.aspx">Account</a></li>
                <li class="hvr-bounce-to-bottom"><a href="../recipes/recipes.aspx">Recipes</a></li>
                <li class="hvr-bounce-to-bottom"><a href="../contact/contact.aspx">Contact</a></li>
            </ul>
        </div>
    <asp:ContentPlaceHolder ID="MainContent" runat="server">
    </asp:ContentPlaceHolder>
</body>
</html>

Index.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="KitchenCounter.pages.Index"  MasterPageFile="~/kitchencounter/master_pages/master_page.Master"%>

<asp:Content runat="server" ContentPlaceHolderID="head">
    <title>Kitchen Counter | Home</title>
    <link rel="stylesheet" href="kitchencounter/css/main.css" />
</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
    The text that is specific for your Index page goes here.
</asp:Content>