View Single Post
  #3 (permalink)  
Old September 5th, 2008, 12:21 AM
mikeal_a mikeal_a is offline
Registered User
 
Join Date: Sep 2008
Location: Phoenix, AZ, .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your reply. Here is both the MasterDemo.Master and MasterDemo.Master.cs

******************
MasterDemo.Master
******************
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterDemo.master.cs" Inherits="MasterPages_MasterDemo" %>

<!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>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div id="PageWrapper">
        <div id="Header">Header<a class="HeaderLink" href="~/" runat="server"><asp:SiteMapDataSource
                ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
            </a></div>
        <div id="MenuWrapper">
            <asp:Menu ID="Menu1" runat="server" CssClass="MainMenu"
                DataSourceID="SiteMapDataSource1" Orientation="Horizontal"
                StaticEnableDefaultPopOutImage="False">
                <StaticSelectedStyle CssClass="StaticSelectedStyle" />
                <StaticMenuItemStyle CssClass="StaticMenuItemStyle" ForeColor="Black" />
                <DynamicHoverStyle CssClass="DynamicHoverStyle" />
                <DynamicMenuItemStyle CssClass="DynamicMenuItemStyle" />
                <StaticHoverStyle CssClass="StaticHoverStyle" />
            </asp:Menu>
        </div>
        <div id="MainContent">
            <asp:ContentPlaceHolder ID="cpMainContent" runat="server">
                <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1"
                    ShowExpandCollapse="False">
                </asp:TreeView>
            </asp:ContentPlaceHolder>
        </div>
        <div id="Sidebar">
            <asp:DropDownList ID="lstPreferredTheme" runat="server" AutoPostBack="True"
                onselectedindexchanged="lstPreferredTheme_Selected IndexChanged">
                <asp:ListItem Value="Monochrome"></asp:ListItem>
                <asp:ListItem>DarkGrey</asp:ListItem>
            </asp:DropDownList>
        </div>
        <div id="Footer">Footer Goes Here</div>
    </div>
    </form>
</body>
</html>

********************
MasterDemo.Master.cs
********************
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class MasterPages_MasterDemo : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string selectedTheme = Page.Theme;
            HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");

            if (preferredTheme != null)
            {
                selectedTheme = preferredTheme.Value;
            }
            if (lstPreferredTheme.Items.FindByValue(selectedTheme ) != null)
            {
                lstPreferredTheme.Items.FindByValue(selectedTheme) .Selected = true;
            }
        }

        switch (Page.Theme.ToLower())
        {
            case "darkgrey":
                Menu1.Visible = false;
                TreeView1.Visible = true;
                break;
            default:
                Menu1.Visible = true;
                TreeView1.Visible = false;
                break;
        }


    }
    protected void lstPreferredTheme_SelectedIndexChanged(object sender, EventArgs e)
    {
        HttpCookie preferredTheme = new HttpCookie("preferredTheme");
        preferredTheme.Expires = DateTime.Now.AddMonths(3);
        preferredTheme.Value = lstPreferredTheme.SelectedValue;
        Response.Cookies.Add(preferredTheme);
        Response.Redirect(Request.Url.ToString());

    }
}

Reply With Quote