Solved

asp.net dynamic master page pulls in its aspx session

Posted on 2010-11-15
3
657 Views
Last Modified: 2012-06-27
can I have a an aspx page that chooses masterpage dynamically...then..that masterpage will lay out the page...then the session varaibles inside the aspx page will be inserted into...see code for sample...
<!--BEGIN MASTER PAGE MARKUP-->

<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site1.master.vb" Inherits="MasterPagesExample.Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <style type="text/css">
        html
        {
            background-color:white;
            font:14px Georgia,Serif;
        }
        .content
        {
            width:700px;
            margin:auto;
            border-style:2px solid black;
            background-color:white;
            padding:10px;
        }
        .header
        {
            width:700px;
            height:100px;
            border:1px solid grey;
        }
        .breadCrumb
        {
            width:700px;
            height:30px;
            border:1px solid red;
        }
        .menu
        {
            width:700px;
            height:30px;
            border:1px solid blue;
        }
        .centerSection
        {
            width:700px;
            height:302px;
        }
        .leftSide
        {
            width:148px;
            height:300px;
            border:1px solid green;
            float:left;
        }
        .mainContent
        {
            width:548px;
            height:300px;
            border:1px solid orange;
            float:right;
        }
        .upperFooter
        {
            width:700px;
            height:80px;
            border:1px solid brown;
        }
        .footer
        {
            width:700px;
            height:60px;
            border:1px solid grey;
        }
        </style>
    <title>Site Master</title>
</head>
<body>
<form id="form1" runat="server">    
<div class="content">
    <div class="header">
        <asp:contentplaceholder id="Header" runat="server">   
			<div>
 				<td>
				</td>
			</div>
 
        </asp:contentplaceholder>
    </div>
    <div class="menu">
        <asp:contentplaceholder id="Menu" runat="server">

<!-- HTML code HERE --->
        </asp:contentplaceholder>
    </div>
    <div class="breadCrumb"> 
        <asp:contentplaceholder id="Bread_Crumb" runat="server">   

<!-- HTML code HERE --->     
        </asp:contentplaceholder>
    </div>
    <div class="centerSection">
        <div class="leftSide">
            <asp:contentplaceholder id="Left_Side_Nav" runat="server"> 

<!-- HTML code HERE --->
            </asp:contentplaceholder>
        </div>
        <div class="mainContent">
            <asp:contentplaceholder id="Main_Content" runat="server"> 

<frameset cols="50%,50%">
    <frame src="frameA.html">
    <frame src="frameB.html">
</frameset>





            </asp:contentplaceholder>
        </div>
    </div>
    <div class="upperFooter">
        <asp:contentplaceholder id="Upper_Footer" runat="server">        
        </asp:contentplaceholder>
    </div>   
    <div class="footer">    
        <asp:contentplaceholder id="Footer" runat="server">              
        </asp:contentplaceholder>
    </div>        
</div>
</form>
</body>
</html>

<!--END MASTER PAGE MARKUP-->



<!--BEGIN WEBFORM1.ASPX MARKUP-->
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="WebForm1.aspx.vb" Inherits="MasterPagesExample.WebForm1" 
    title="Untitled Page" %>


<script runat="server">

   Protected Overrides Sub OnPreInit(ByVal e As EventArgs)
      
        ' overide the curent masterpage
        Page.MasterPageFile = Session("SelectedTheme")


        MyBase.OnPreInit(e)
    End Sub


</script>


<asp:Content ID="Content1" ContentPlaceHolderID="Header" runat="server">
<p>Header content</p><br />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Bread_Crumb" runat="server">
<p>Bread_Crumb content</p>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Menu" runat="server">
<p>Menu content</p>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Left_Side_Nav" runat="server">

<%=Session("SessionThis_page_menu")%>

<p>Left_Side_Nav content</p>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Main_Content" runat="server">

<%=Session("SessionMain_content")%>
%=Session("SessionMain_content1")%>
%=Session("SessionMain_content2")%>

<p>Main content</p>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Upper_Footer" runat="server">
<p>Upper_Footer content</p>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="Footer" runat="server">
<p>Footer content</p>
<center>Copyright &copy; 2010 by Dty</center>
</asp:Content>

<!--END WEBFORM1.ASPX MARKUP-->

Open in new window

0
Comment
Question by:GlobaLevel
3 Comments
 
LVL 10

Author Comment

by:GlobaLevel
ID: 34139027
?
0
 
LVL 21

Accepted Solution

by:
Alfred1 earned 500 total points
ID: 34142770
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 34148053
If you are looking to use different themes, I suggest you look in to theming asp.net applications, it's a simpler way to do what you are trying to accomplish.

http://msdn.microsoft.com/en-us/library/ykzx33wh.aspx
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question