 |
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
|
|
|
|

December 5th, 2010, 07:31 PM
|
Authorized User
|
|
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
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
|

December 6th, 2010, 05:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

December 6th, 2010, 05:24 AM
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 22
Thanks: 2
Thanked 10 Times in 7 Posts
|
|
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:
|
|

December 6th, 2010, 02:49 PM
|
Authorized User
|
|
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
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
|

December 6th, 2010, 04:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

December 6th, 2010, 06:52 PM
|
Authorized User
|
|
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Dark_grey not found
I guess I imagined it. Thanks for looking.
|
|
 |
|