Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling session variable within @page syntax for master name

Status
Not open for further replies.

ifntech

Programmer
Nov 4, 2004
80
0
0
US
I would like to replace the master name with a session value.

What would the proper syntax be to do this

<%@ Page EnableSessionState ="True" Debug ="true" Language="VB" MasterPageFile ="~/mysessionvalue.master" %>

Visual Studio Web Developer has not liked anyway I've tried to call it.

Thanks for the help in advance.
 
Sorry for being dense, but do you mean something like this.


Isn't there a way I can just pull the session value directly in the code line. But I'm sure this syntax is incorrect.

<%@ Page EnableSessionState ="True" Debug ="true" Language="VB" MasterPageFile ="~/home_<%=Request.Session.Content("mysession") %>.master" %>

I need to have multiple masters drivin by the session value.
I want the new master to be pulled up on a change in the session value.
 
Set the Page.MasterPageFile property (that I pointed out above) on the page load event.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I looked at that but unsure how to make the dynamic masterpage file within the code. Unsure on how that is added to the current code.
 
Isn't there a way just to do it something like this with syntax correction.

<%@ Page EnableSessionState ="True" Debug ="true" Language="VB" MasterPageFile ="~/home_<%=Request.Session.Content("mysession") %>.master" %>

I need to have multiple masters drivin by the session value.
I want the new master to be pulled up on a change in the session value.


 
I just have a question - you seem to be very resistant to take advantage of using the code behind model to ASP.Net.


Why is this?

You can save a lot of time and energy trying to get inline ASP to work by just performing your tasks in code.

In your Page_PreInit Event put

Code:
Page.MasterPageFile = Request.Session("mysession").Value


At the risk of sounding like a b*tch, I'm going to make a comment. This is at least how i feel. It is hard for me(us) to help you with your questions when you are so resistant to using the OOP methodologies that .Net offers. My(Our) suggestions and/or help is more than likely going to be OO oriented. Although inline ASP can be used in the page, why clutter the seperation that ASP.Net gives you with your HTML and your code?

If you're programming in .Net after using classic ASP, like I think you've used in the past, there are changes to the approach you take towards solving your problem. .Net is OO, and everyone that uses it is cheating themselves of taking advantage of the framework if they aren't programming OO.

Anyhow, with that said..

If you use the code approach to solve your problem like we suggested, it needs to go into the Page_PreInit event or in an event before that in order to work.


 
Ok, I have put code behind in ASP.NET page
<script>

Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Page.MasterPageFile = Session.Contents("myMaster").Value
End Sub

</script>
in the Master page I have put the code
<script>
Session.Contents("myMaster") = "Home_session.master"
</script>

But the ASP.NET page doesn't allow me to run. It doesn't recognize the content holders in asp.net page. What else I should change? Is that the right syntax so far?
 
Can you post all of your code? The master page, and the aspx page that inherits this mater page?
 
Code in ASP page

<%@ Page Language="VB" EnableSessionState ="true" AutoEventWireup ="true" %>

Code in master page

<%@ Master Language="VB" %>
 
I have a few pages with
<asp:Content></asp:content>
they inherit the master page.
 
I meant ALL code for the pages, not just the bits and pieces.
 
Here is the code, if you want me to clean it up - let me know.

ASP.NET page:

Now that's relevant.

<%@ Page Language="VB" EnableSessionState ="true" AutoEventWireup ="true" %>

<script runat="server" >

Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Page.MasterPageFile = Session.Contents("myMaster").Value
End Sub
</script>
<asp:Content ID="TopBorder" ContentPlaceHolderID = "MainContent" runat ="server" >
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString1 %>" ProviderName="<%$ ConnectionStrings:testConnectionString1.ProviderName %>"
SelectCommand="SELECT wp_navigation.link, wp_page_content.page_cont_id, wp_page_content.interface_id, wp_page_content.language, wp_page_content.contentholder, wp_page_content.page_content FROM wp_navigation INNER JOIN wp_page_content ON wp_navigation.interface_id = wp_page_content.interface_id WHERE (wp_navigation.link = @link and wp_page_content.language = @language)">
<SelectParameters>
<asp:SessionParameter DefaultValue="English" Name="language" SessionField="language" Type="String" />
<asp:QueryStringParameter DefaultValue="filename.aspx" Name="link" QueryStringField="pn" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="page_contentLabel" runat="server" Text='<%# Bind("page_content") %>' Height="268px" Width="394px"></asp:Label>
</ItemTemplate>

</asp:FormView>
</asp:content>


Master page:
It's long and irrelevant but here it is.
<%@ Master Language="VB" %>

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Set Session Variable language equal to English
Session.Timeout = 40
Session.Contents("language") = "English"
Session.Contents("myMaster") = "Home_english.master"
End Sub
</script>

<html>
<head runat ="server">
<title>Mypage </title>
<link href = "StyleSheet.css" rel = "stylesheet" type = "text/css" />

</head>
<body bgcolor="#d4d0c8" topmargin ="0" vlink = "deepskyblue" ><center >
<form runat ="server" id="form1">
<Table ID="Table1" cellpadding ="0" border ="0" cellspacing="0" visible = "false" hidefocus =hidefocus bgcolor="white" width="800" >
<tr bgcolor ="black" >
<td colspan="3" align="right" style="color: white; font-size :medium; font-family: Verdana, Arial, 'Century Gothic'; font-size: 8px;">
<asp:Button ID="FrenchID" runat="server"
ForeColor="Black" Text="French" OnClick="FrenchID_Click"/>| <asp:Button ID="SpanishID" runat="server"
ForeColor="Black" Text="Spanish" OnClick="SpanishID_Click"/></td></tr>
<tr valign = "top" height = "100%">
<td colspan = 2 valign ="top" align ="left" bgcolor ="black" >
<img align ="bottom" ID="Image2" runat="server" alt="[Logo]" src ="~/Images/logo_home_new.jpg" />
</td>
<td valign ="top" align = "left" width ="100%" bgcolor="black" >
<img align = "bottom" id = "Image3" runat = "server" alt="[Top Border]" src ="~/Images/top_border.jpg" /><br />
<table height = "30px" cellpadding ="0" cellspacing="0" width = "100%" >
<tr width = "300" valign ="top" >
<td align = "right" style =" color :White ; font-family: Verdana; font-size: x-small ; font-style: normal ">
<b><a href ="Home.aspx">Home</a> | <a href ="Company.aspx" >Company</a> | <a href ="Product.aspx" >Product</a> | <a href = "News.aspx">Newsroom</a> | <a href ="ContactUs.aspx" >Contact</a></b>
<br/>
<asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="0.8em" PathSeparator=" : ">
<PathSeparatorStyle Font-Bold="True" ForeColor="white" />
<CurrentNodeStyle ForeColor="wheat" />
<NodeStyle Font-Bold="True" ForeColor="skyblue" />
<RootNodeStyle Font-Bold="True" ForeColor="deepskyblue" />
</asp:SiteMapPath></td>
</tr></table>


</td>

<td valign ="top" align = "left" width = "200" height ="100%" >
<table cellspacing ="0" cellpadding ="0" height ="100%" > <tr valign ="top" height ="100%"><td bgcolor="#1E90FF" bordercolor ="#1E90FF" width="200" height ="100%">
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
&nbsp;
<asp:Menu ID="Menu2" runat="server" BackColor="#1E90FF" DataSourceID="SiteMapDataSource1"
DynamicHorizontalOffset="2" Font-Bold ="true" Font-Names="Verdana" Font-Size="0.8em" ForeColor="wheat"
StaticSubMenuIndent="10px" StaticDisplayLevels="2">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#284E98" ForeColor="White" Font-Bold = "true" />
<DynamicMenuStyle BackColor="black" />
<DynamicItemTemplate>
<%# Eval("Text") %>
</DynamicItemTemplate>
<StaticSelectedStyle BackColor="#507CD1" />
<DynamicSelectedStyle BackColor="#507CD1" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#507CD1" ForeColor="White" Font-Bold ="true" />
</asp:Menu></td><td>
<table cellspacing ="0" bgcolor ="black" cellpadding ="0" width =40 height ="100%"><tr><td>&nbsp;</td></tr></table>
</td> </tr></table>
</td>
<td>
<table cellspacing ="0" height="100%">
<tr>
<td colspan =2><asp:ContentPlaceHolder ID="MainContent" runat="server">
<table height ="100%">
<tr>
<td>
&nbsp;
</td>
</tr>
</table>
</asp:ContentPlaceHolder></td>
</tr>
<tr>
<td style="height: 234px"><asp:contentplaceholder id="LeftTopContent" runat="server" >
</asp:contentplaceholder></td>
<td style="height: 234px" ><asp:ContentPlaceHolder ID="RightTopContent" runat="server">
</asp:ContentPlaceHolder></td>
</tr>
<tr>
<td><asp:ContentPlaceHolder ID="LeftBotContent" runat="server">
</asp:ContentPlaceHolder></td>
<td><asp:ContentPlaceHolder ID="RightBotContent" runat="server">
</asp:ContentPlaceHolder></td>
</tr>
</table>
</td>
</tr>

</Table>
</form>
</center></body>
</html>
 
Yesterday I told you what event this had to go in.

Page_PreInit.

Your code sets the Page.MasterPageFile in Page_Load. This will not work.

Modify your code to this

Code:
<%@ Page Language="VB"   EnableSessionState ="true"  AutoEventWireup ="true"  %>

<script runat="server" >

Public Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
    Page.MasterPageFile = Session.Contents("myMaster").Value
End Sub
</script>  

<snipped....>
 
If you don't mind I will come back to this question in a few days. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top