Hi Imar, I think I'm just running into constant problem on my second read though of this book! Im on Chapter 6 now, on the programmatically changing the themes. I have done the drop down list, cookies and the page class, of which it inherits, with some code that should apply the theme from a cookie in the page pre init stage of the life cycle. The first problem is that the cookie isnt implementing the previous state of the drop down list on a page refresh, its just being stored in the view state. The second, which may be seen as the biggest, is that it dosent work
Anyways here are my files!

I'm keeping you busy lol...
~/Masterpages/Default.master
Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Default.master.cs" Inherits="Masterpages_Default" %>
<!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 id="wrapper"> <asp:Label ID="Label1" runat="server" />
<div id="top">
<div id="navigation">
<ul>
<li><asp:HyperLink ID="HyperLink2" NavigateUrl="~/Browse/" runat="server">Browse</asp:HyperLink></li>
<li><asp:HyperLink ID="HyperLink1" NavigateUrl="~/Browse/" runat="server">Browse</asp:HyperLink></li>
<li><asp:HyperLink NavigateUrl="~/Browse/" runat="server">Browse</asp:HyperLink></li>
</ul>
</div><!-- End of Navigation -->
<div id="header">
<asp:HyperLink NavigateUrl="~/" runat="server">
<asp:Image ImageUrl="~/App_Themes/Default/Images/logo.png" runat="server" />
</asp:HyperLink><!-- End of Logo -->
<div class="advert">
<asp:HyperLink NavigateUrl="http://www.woothemes.com/" runat="server">
<asp:Image ID="Image1" ImageUrl="~/App_Themes/Default/Images/468x60a.jpg" runat="server" />
</asp:HyperLink>
</div><!-- End of Top Ad -->
</div><!-- End of Header -->
</div><!-- End of Top -->
<div class="content">
<div class="main-content">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div><!-- End of Main Content -->
<div id="sidebar">
<span>Select a theme:</span>
<asp:DropDownList ID="ThemePicker" AutoPostBack="true" SelectedIndexChanged="ThemePicker_SelectedIndexChanged" Width="100%" runat="server">
<asp:ListItem>Default</asp:ListItem>
<asp:ListItem>Dark</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Red</asp:ListItem>
</asp:DropDownList>
</div><!-- End of Sidebar -->
</div><!-- End of Content -->
</div><!-- End of Wrapper -->
</form>
</body>
</html>
~/Masterpages/Default.master.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Masterpages_Default : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string selectedTheme = Page.Theme;
HttpCookie themeOption = Request.Cookies.Get("ThemeOption");
if (themeOption != null)
{
selectedTheme = themeOption.Value;
}
if (!string.IsNullOrEmpty(selectedTheme) && ThemePicker.Items.FindByValue(selectedTheme) != null)
{
ThemePicker.Items.FindByValue(selectedTheme).Selected = true;
}
}
}
protected void ThemePicker_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie themeOption = new HttpCookie("ThemeOption");
themeOption.Expires = DateTime.Now.AddMonths(3);
themeOption.Value = ThemePicker.SelectedValue;
Response.Cookies.Add(themeOption);
Response.Redirect(Request.Url.ToString());
}
}
~/Default.aspx
Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Masterpages/Default.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>Hello this is some test content!</p>
</asp:Content>
~/Default.aspx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
~/web.config
Code:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<pages theme="Default"></pages>
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>
~/App_Code/BasePage.cs
Code:
using System;
using System.Web;
/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage : System.Web.UI.Page
{
private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie themeOption = Request.Cookies.Get("ThemeOption");
if (themeOption != null)
{
Page.Theme = "Dark";
}
}
public BasePage()
{
this.PreInit += new EventHandler(Page_PreInit);
}
}
Then I have App_Themes containing two themes call Default and Dark. They both have sub folders call Images and a stylesheet.
I hope you can spot an error that I am totaly stumped off lol. I think its gunna need yet another re-read (the whole book).
Oh, Imar, from the last thread. I wasnt intending on being narrow minded on the
VB.net syntax, its just so radically different than anyother. I will probably learn it for freelancing and updating current
VB.net application. (If I ever get any good at ASP.net that is)....
Thanks again! / Ryan