E
Elroyskimms
I'm new to Master Pages so if this is an easy fix, I apologize in
advance.
I have 4 files in a website: default.aspx, Root.Master, M2.Master,
UC1.ascx
default.aspx is accessed via a web browser. Its Master Page is set to
Root.Master:
<%@ Page Language="vb" MasterPageFile="~/Root.Master" %>
<script runat="server">
</script>
<asp:Content ID="defaultContentArea" runat="server"
ContentPlaceHolderID="cphDefault">
<div style="background-color: Blue; color: White; font-size:
larger">
<table width="100%">
<tr valign="middle">
<td>
Menu Item</td>
<td>
Menu Item</td>
</tr>
</table>
</div>
</asp:Content>
___________________________________________
Root.Master has 2 ContentPlaceHolders. The top holder (cphDefault) is
where default.aspx will be loaded (this appears to be working fine.
The bottom ContentPlaceHolder is cphRoot and M2.Master is set to have
cphRoot as its Content Holder. I add M2.Master to cphRoot at runtime:
<%@ Master Language="VB" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
cphRoot.Controls.Add(Page.LoadControl("~/M2.Master"))
End Sub
</script>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="5" cellspacing="0" style="border:
solid medium red;" width="100%">
<tr valign="top">
<td style="border: solid thick blue;">
<asp:ContentPlaceHolder ID="cphDefault"
runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
<tr valign="top">
<td style="border: solid thick green;">
<asp:ContentPlaceHolder ID="cphRoot"
runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
_______________________________________________
M2master has one ContentPlaceHolder. I add UC1.ascx to the
LeftContentArea at runtime. Please note that I have tried this code on
the Init and Load events, but the outcome is the same:
<%@ Master Language="VB" MasterPageFile="~/Root.Master" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
LeftContentArea.Controls.Add(Page.LoadControl("~/UC1.ascx"))
End Sub
</script>
<asp:Content ID="M2Content" runat="server"
ContentPlaceHolderID="cphRoot">
M2
<table width="100%" cellpadding="0" border="5">
<tr valign="top">
<td width="50%">
<asp:ContentPlaceHolder ID="LeftContentArea"
runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</asp:Content>
__________________________________________
The code runs fine until M2.Master tried to add UC1.ascx to the
LeftContentArea. LeftContentArea is always nothing so the load fails.
I've tried every possible combination of Init and Load events for both
Master pages. I've also tried creating a new instance of a
ContentPlaceHolder and assigning that to Me.LeftContentArea before
loading the UC1.ascx control. Although this runs fine, the user
control is not visible when the page loads into the browser.
What I am trying to accomplish is to populate the cphRoot
ContentPlaceHolder (in Root.Master) with a different Master page which
will then display a Web User Control. The idea is to be able to load
various layout Master pages at runtime and then fill their dynamically
generated ContentPlaceHolders with Web User Controls. Please help!
Thanks,
-E
advance.
I have 4 files in a website: default.aspx, Root.Master, M2.Master,
UC1.ascx
default.aspx is accessed via a web browser. Its Master Page is set to
Root.Master:
<%@ Page Language="vb" MasterPageFile="~/Root.Master" %>
<script runat="server">
</script>
<asp:Content ID="defaultContentArea" runat="server"
ContentPlaceHolderID="cphDefault">
<div style="background-color: Blue; color: White; font-size:
larger">
<table width="100%">
<tr valign="middle">
<td>
Menu Item</td>
<td>
Menu Item</td>
</tr>
</table>
</div>
</asp:Content>
___________________________________________
Root.Master has 2 ContentPlaceHolders. The top holder (cphDefault) is
where default.aspx will be loaded (this appears to be working fine.
The bottom ContentPlaceHolder is cphRoot and M2.Master is set to have
cphRoot as its Content Holder. I add M2.Master to cphRoot at runtime:
<%@ Master Language="VB" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
cphRoot.Controls.Add(Page.LoadControl("~/M2.Master"))
End Sub
</script>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="5" cellspacing="0" style="border:
solid medium red;" width="100%">
<tr valign="top">
<td style="border: solid thick blue;">
<asp:ContentPlaceHolder ID="cphDefault"
runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
<tr valign="top">
<td style="border: solid thick green;">
<asp:ContentPlaceHolder ID="cphRoot"
runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
_______________________________________________
M2master has one ContentPlaceHolder. I add UC1.ascx to the
LeftContentArea at runtime. Please note that I have tried this code on
the Init and Load events, but the outcome is the same:
<%@ Master Language="VB" MasterPageFile="~/Root.Master" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
LeftContentArea.Controls.Add(Page.LoadControl("~/UC1.ascx"))
End Sub
</script>
<asp:Content ID="M2Content" runat="server"
ContentPlaceHolderID="cphRoot">
M2
<table width="100%" cellpadding="0" border="5">
<tr valign="top">
<td width="50%">
<asp:ContentPlaceHolder ID="LeftContentArea"
runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</asp:Content>
__________________________________________
The code runs fine until M2.Master tried to add UC1.ascx to the
LeftContentArea. LeftContentArea is always nothing so the load fails.
I've tried every possible combination of Init and Load events for both
Master pages. I've also tried creating a new instance of a
ContentPlaceHolder and assigning that to Me.LeftContentArea before
loading the UC1.ascx control. Although this runs fine, the user
control is not visible when the page loads into the browser.
What I am trying to accomplish is to populate the cphRoot
ContentPlaceHolder (in Root.Master) with a different Master page which
will then display a Web User Control. The idea is to be able to load
various layout Master pages at runtime and then fill their dynamically
generated ContentPlaceHolders with Web User Controls. Please help!
Thanks,
-E