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 December 5th, 2010, 07:31 PM
Authorized User
 
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default Theme switching won't "stick"

I've setup the DropDown box to switch themes, but what happens is the Monochrome theme displays, I select DarkGrey, the page reloads, then the theme and the DropDown box both revert to monochrome.

I've zipped up my site and put it in a Google Doc:

Zip file of site is here.

TIA

--
Knute
 
Old December 6th, 2010, 05:21 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 Knute,

You forgot to add the cookie you created to the Cookies collection in the ThemeList_SelectedIndexChanged method. It's the bold line in the following code block:

Code:
 
HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = ThemeList.SelectedValue;
Response.Cookies.Add(preferredTheme);
Response.Redirect(Request.Url.ToString());
Once you fix that, you'll get an error about the theme DarkGrey not being found. That's because your theme folder is called Dark_Grey, not DarkGrey. Once you fix that as well, the theme switcher works.

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!
The Following User Says Thank You to Imar For This Useful Post:
ksnortum (December 6th, 2010)
 
Old December 6th, 2010, 05:24 AM
Authorized User
 
Join Date: Oct 2009
Posts: 22
Thanks: 2
Thanked 10 Times in 7 Posts
Default

The code in the Frontend.master

Code:
protected void ThemeList_SelectedIndexChanged(object sender, EventArgs e)
    {
      HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
      preferredTheme.Expires = DateTime.Now.AddMonths(3);
      preferredTheme.Value = ThemeList.SelectedValue;
      Response.Redirect(Request.Url.ToString());
    }
is missing a

Code:
Response.Cookies.Add(preferredTheme);
which actually sets the cookie. You need this line just before you do the redirect.
The Following User Says Thank You to walbalooshi For This Useful Post:
ksnortum (December 6th, 2010)
 
Old December 6th, 2010, 02:49 PM
Authorized User
 
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default I works

Thanks guys, that was it. Funny how I knew the cookie wasn't getting writen and I looked at that section of code but missed the .add() line.

The problems with "DarkGrey" versus "Dark_Grey" are in the book. You are told on page 227, step 3 of Try it Out to add DarkGrey (no underscore) to the DropDownList. I haven't looked in the errata but it seems like a candidate.

Thanks again.

--
Knute
 
Old December 6th, 2010, 04:17 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
You are told on page 227, step 3 of Try it Out to add DarkGrey (no underscore) to the DropDownList.
That's absolutely correct, but Dark_Grey with an underscore is nowhere to be found in the book ;-)

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!
 
Old December 6th, 2010, 06:52 PM
Authorized User
 
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default Dark_grey not found

I guess I imagined it. Thanks for looking.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulties with "web.config" and "ASPNETDB" CFRham BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 2 July 3rd, 2010 10:19 AM
Need code corrections "get sub or function not defined" error" bluesboytoo Excel VBA 1 October 22nd, 2009 11:12 PM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM





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