locked
Nested Master Pages RRS feed

  • Question

  • User-956690817 posted
    I tried to do the video tutorial how do I create nested master pages in Visual Studio 2008

    I have VS2008 standard editon with 3.5 SP1 and I dont have any of these templates

    nor can I find them any where for download or install them or did they do away with the idea of nested master pages with 3.5 sp1 any Ideas

    Thursday, October 23, 2008 3:06 AM

Answers

  • User-1167255018 posted

    Hello There,

    you are almost there, 2 changes.

    first in you child Master Page add a <asp:ContentPlaceHolder> inside the <asp:content id="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    so your child MasterPage will look like this now

    <%@ Master Language="C#" AutoEventWireup="true" MasterPageFile="~/Main.master" CodeFile="Child.master.cs" Inherits="Child" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <h4>this is child master using contentplaceholder id = head</h4>

    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <h4>Welcome to Child Master Page. I am using Contentplaceholder id = ContentPlaceHolder1</h4>

    <asp:ContentPlaceHolder ID="cpChild" runat="server">

    </asp:ContentPlaceHolder>

    </asp:Content>

    now in your aspx.page

    <%@ Page Language="C#" MasterPageFile="~/Child.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>

    <%-- Add content controls here --%>

    <asp:content id="cMain" runat="server" contentplaceholderid="cpChild" >

    <div id="cats" runat="server">

    <asp:Image ID="Image1" runat="server" ImageUrl="~/images/curleft.jpg" /></div>

     

    </asp:content>

    now it will run.

    Hope this helps !!

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 23, 2008 1:22 PM
  • User-538256727 posted

     just a note on novicehere's post: you don't have to change the placeholder id in your nested masterpage. You can just do:

    <asp:Content id="content2" runat="server" ContentPlaceHolderID="ContentPlaceholder1">
      <asp:ContentPlaceholder runat="server" id="ContentPlaceholder1" />
    </asp:Content>

    this way, if you ever decide to remove the nested masterpage, your contentpages won't break cause they'll find the placeholder in the root master.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 23, 2008 3:01 PM

All replies

  • User-538256727 posted

    Hi,

    they certainly have not discontinued it! I think you might be overlooking the fact that nested masterpages are just masterpagesthat inherit from other masterpages.

    So just use the Master Page template in (web > c#)

    Thursday, October 23, 2008 6:21 AM
  • User-956690817 posted

    I tried that while watching the vides tutorial it acted no differnt than than a regular aspx page other than the nestedmaster page wont display  

    any content untill I add a content page to the nestedmaster then any content I put in the nestedmaster page displays if I try to put any content

    in the aspx page I added I get an error

    this is  the nestedmaster

    <%@ Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MasterPage2.master.cs" Inherits="MasterPage2" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div style="height: 136px"></div>

    </asp:Content>

    and this is the content page

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

    <%-- Add content controls here --%>

    when I try to put anything inthe content page I get this error

    System.Web.HttpException: Content controls have to be top-level controls in a content page or a nested master page that references a master page<?xml:namespace prefix = asp /><asp:Content class=st id="

     
    </asp:Content>
     
    Thursday, October 23, 2008 11:56 AM
  • User-1167255018 posted

     

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    Hello There,

    do you have that contentplaceholderid in you main master page ( parent master page) for both <asp:content>

    Thanks

     

     

    Thursday, October 23, 2008 12:30 PM
  • User-1167255018 posted

    Hello There,

    you are almost there, 2 changes.

    first in you child Master Page add a <asp:ContentPlaceHolder> inside the <asp:content id="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    so your child MasterPage will look like this now

    <%@ Master Language="C#" AutoEventWireup="true" MasterPageFile="~/Main.master" CodeFile="Child.master.cs" Inherits="Child" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <h4>this is child master using contentplaceholder id = head</h4>

    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <h4>Welcome to Child Master Page. I am using Contentplaceholder id = ContentPlaceHolder1</h4>

    <asp:ContentPlaceHolder ID="cpChild" runat="server">

    </asp:ContentPlaceHolder>

    </asp:Content>

    now in your aspx.page

    <%@ Page Language="C#" MasterPageFile="~/Child.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>

    <%-- Add content controls here --%>

    <asp:content id="cMain" runat="server" contentplaceholderid="cpChild" >

    <div id="cats" runat="server">

    <asp:Image ID="Image1" runat="server" ImageUrl="~/images/curleft.jpg" /></div>

     

    </asp:content>

    now it will run.

    Hope this helps !!

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 23, 2008 1:22 PM
  • User-538256727 posted

     just a note on novicehere's post: you don't have to change the placeholder id in your nested masterpage. You can just do:

    <asp:Content id="content2" runat="server" ContentPlaceHolderID="ContentPlaceholder1">
      <asp:ContentPlaceholder runat="server" id="ContentPlaceholder1" />
    </asp:Content>

    this way, if you ever decide to remove the nested masterpage, your contentpages won't break cause they'll find the placeholder in the root master.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 23, 2008 3:01 PM
  • User-1167255018 posted

    True [:P]

    Thanks

    Thursday, October 23, 2008 3:11 PM
  • User-956690817 posted

    Thanks that was fast good move

    Thursday, October 23, 2008 3:58 PM