Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2012, 11:41 AM
Registered User
 
Join Date: Aug 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to granola911 Send a message via Yahoo to granola911
Default Chapter 6 - theme not changing

Hi Imar,

I am working with chap 6. I have checked my code and it looks fine, but maybe i'm missing something. When i change the theme using the dropdown list, i can see the postback take place, but the theme does''t change. From what I can gather, it looks like the cookies are working, but I do have other cookies in my Temp Internet files, but not PerferredTheme...

Thanks for any help.

Code:

Web config:
Code:
<?xmlversion="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>
<compilationdebug="true"targetFramework="4.0"/>
<pagestheme="Monochrome"></pages>
</system.web>
</configuration>
FronEnd.Master
Code:
<%@MasterLanguage="C#"AutoEventWireup="true"CodeFile="FrontEnd.master.cs"Inherits="MasterPages_FrontEnd" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<asp:ContentPlaceHolderid="head"runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<formid="form1"runat="server">
<divid="PageWrapper">
<divid="Header"><ahref="-/"runat="server"></a></div>
<divid="MenuWrapper">Menu</div>
<divid="MainContent">
<asp:ContentPlaceHolderID="cpMain"runat="server">
</asp:ContentPlaceHolder>
</div>
<divid="Sidebar">
<asp:DropDownListID="theme"runat="server"AutoPostBack="True"onselectedindexchanged="theme_SelectedIndexChanged">
<asp:ListItemValue="DarkGrey"></asp:ListItem>
<asp:ListItemValue="Monochrome"></asp:ListItem>
</asp:DropDownList>
</div>
<divid="Footer">Footer goes here</div>
</div>
</form>
</body>
</html>

FrontEnd.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassMasterPages_FrontEnd : System.Web.UI.MasterPage
{
protectedvoid 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 (!string.IsNullOrEmpty(selectedTheme) && theme.Items.FindByValue(selectedTheme) != null)
{
theme.Items.FindByValue(selectedTheme).Selected = true;
}
}
}
protectedvoid theme_SelectedIndexChanged(object sender, EventArgs e)
{
HttpCookie preferredTheme = newHttpCookie("PreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = theme.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
}
}

Last edited by granola911; January 2nd, 2012 at 09:42 PM..
 
Old January 4th, 2012, 09:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is the page you're testing this on inheriting the BasePage? In other words, did you change System.Web.UI.page in the Code Behind to BasePage?

If that's not the solution, can you also post the code for the BasePage and repost your existing code? If you paste code, can you please copy it to Notepad first to remove color coding? Due to some stupid bug in this forum, colored code is messed up when you wrap it in code tags (many relevant spaces get lost).

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
weird behaviour - chapter 6 User-selected theme lornarmac BOOK: Beginning ASP.NET 4 : in C# and VB 1 December 2nd, 2010 06:36 AM
chapter 6 p226 preferred theme in basepage robbaralla BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 November 7th, 2009 11:24 AM
Chapter 18: Unable to see the site THEME locochinoloco BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 September 18th, 2008 02:35 AM
Chapter 6 User-Selected Theme Question jabo2099 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 August 21st, 2008 03:45 AM
Theme Selector wont pick up other theme Tawanda BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 May 4th, 2007 08:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.