You need to load content in one contentplaceholder.
for example:
in your master page place one ContentPlaceHolderand in each .aspx place <content> and put you content there.
If you want to put some other content in master without contentplaceholder you can use placeholder and put content there programatically.
I place content which needs to be loaded only in few pages and only with exact permissions in <asp:PlaceHolder ID="menuPlaceHolder" runat="server"></asp:PlaceHolder>
Placeholder can be empty, and i can load content programatically there from any .aspx page in my project.
Continue example from my project: I use setting.aspx.cs to load content to asp:PlaceHolder
In simple terms, you cannot have more than one page for a masterpage. You can only have a one child page for a master page at a time. That's how it works. If you need to replace contentplaceholders like this, you have to use nested master page. But again,
you can use only one child page.
madsoveniels...
0 Points
7 Posts
Multiple content placeholders in masterpage
Aug 16, 2012 06:40 PM|LINK
Hello
I am trying to learn the concept of masterpages, i have the following code:
Masterpage.master
<%@ Master Language="VB" AutoEventWireup="true" CodeBehind="Masterpage.master.vb" Inherits="VUC_test.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 runat="server"> <title></title> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <div style="float: left; width: 220px; background: #ECECEC;"> <asp:ContentPlaceHolder ID="Menu" runat="server"></asp:ContentPlaceHolder> </div> <div style="float: left;"> <asp:ContentPlaceHolder ID="Content" runat="server"></asp:ContentPlaceHolder> </div> </div> </form> </body> </html>Default.aspx
menu.aspx
Howerver, only the content from Default.aspx is being displayed, i can't understand why.
Kind regards
Daniil T.
Member
46 Points
32 Posts
Re: Multiple content placeholders in masterpage
Aug 16, 2012 10:52 PM|LINK
Try to use empty <asp:Content>.
For example for Default.aspx
and for menu
I think the problem, that you are leaving one of two content place holder not set although in master page you specified two placeholders.
madsoveniels...
0 Points
7 Posts
Re: Multiple content placeholders in masterpage
Aug 17, 2012 08:50 AM|LINK
Hello
Yes, it works if i have all the content in one file, but that is not what i want.
Masterpage.master
<%@ Master Language="VB" AutoEventWireup="true" CodeBehind="Masterpage.master.vb" Inherits="VUC_test.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 runat="server"> <title></title> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <div style="float: left; width: 220px; background: #ECECEC;"> <asp:ContentPlaceHolder ID="Menu" runat="server"></asp:ContentPlaceHolder> </div> <div style="float: left;"> <asp:ContentPlaceHolder ID="Content" runat="server"></asp:ContentPlaceHolder> </div> </div> </form> </body> </html>Default.aspx
Daniil T.
Member
46 Points
32 Posts
Re: Multiple content placeholders in masterpage
Aug 18, 2012 03:50 PM|LINK
Could you explain what you want?
Perhaps i misunderstood you.
My thoughts:
You don`t need to create contentplace holder for evert page. In you case you can use one placeholder.
madsoveniels...
0 Points
7 Posts
Re: Multiple content placeholders in masterpage
Aug 18, 2012 04:35 PM|LINK
Yes, no problem. :)
I would like to have a .aspx file for each content placeholder.
Daniil T.
Member
46 Points
32 Posts
Re: Multiple content placeholders in masterpage
Aug 18, 2012 10:29 PM|LINK
Why you need that ?
You need to load content in one contentplaceholder.
for example:
in your master page place one ContentPlaceHolder and in each .aspx place <content> and put you content there.
If you want to put some other content in master without contentplaceholder you can use placeholder and put content there programatically.
Example from my project.
Maste:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Main.Master.cs" Inherits="WEB_GUI_Simple.WebGUI" %> <!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> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /> <title>M2DT</title> <link href="css/normalize.css" rel="stylesheet" type="text/css" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="mainForm" runat="server"> <div class="clouds"></div> <div class="top-line"></div> <div class="paper-bird"></div> <div runat="server" id="topMenu" class="top-menu"> <asp:PlaceHolder ID="menuPlaceHolder" runat="server"></asp:PlaceHolder> </div> <div class="logout"> <asp:Button ID="LogOut" CssClass="logOutButton" runat="server" OnClick="LogOut_Click" /> </div> <asp:ContentPlaceHolder ID="ContentPlaceHolder" runat="server"> </asp:ContentPlaceHolder> <div runat="server" id="sideToolBox" class="side-toolbox"> <ul class="navigation"> <li> <asp:HyperLink ID="docLink" runat="server" NavigateUrl="#"> <img src="images/tool_icon_01.png" alt="Dokumentai" /> </asp:HyperLink> </li> <li> <asp:HyperLink ID="formLink" runat="server" NavigateUrl="#"> <img src="images/tool_icon_02.png" alt="Formos" /> </asp:HyperLink> </li> <li> <asp:HyperLink ID="settingLink" runat="server" NavigateUrl="~/settings.aspx"> <img src="images/tool_icon_03.png" alt="Nustatymai" /> </asp:HyperLink> </li> <li> <asp:HyperLink ID="faqLink" runat="server" NavigateUrl="~/faq.aspx"> <img src="images/tool_icon_04.png" alt="D.U.K." /> </asp:HyperLink> </li> </ul> </div> </form> </body> </html>I place content which needs to be loaded only in few pages and only with exact permissions in <asp:PlaceHolder ID="menuPlaceHolder" runat="server"></asp:PlaceHolder>
Placeholder can be empty, and i can load content programatically there from any .aspx page in my project.
Continue example from my project:
I use setting.aspx.cs to load content to asp:PlaceHolder
Page.Master.FindControl("MenuPlaceHolder").Controls.Add(llinkHelper.GetLinkGroup("&(i+1).ToString&"));llinkHelper.GetLinkGroup("&(i+1).ToString&") - is my function that i wrote.
In your case you`ll need to create new object for example div ant put your desirable content in innerHtml atributte.
Finally it would look like this
Page.Master.FindControl("asp:PlaceHolderID").Controls.Add(YourNewCreatedObjectName);Hope it will help you. If not, write it down - you problem - we`ll try to help you. :)
Ruchira
All-Star
43056 Points
7040 Posts
MVP
Re: Multiple content placeholders in masterpage
Aug 20, 2012 12:12 PM|LINK
Hello,
In simple terms, you cannot have more than one page for a masterpage. You can only have a one child page for a master page at a time. That's how it works. If you need to replace contentplaceholders like this, you have to use nested master page. But again, you can use only one child page.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.