View Single Post
  #12 (permalink)  
Old April 8th, 2012, 05:08 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

A few things I noticed / wondered....

1. Is Themes_SelectedIndexChanged being called? E.g. did you set AutoPostBack on the control to true? have you tried putting a breakpoint in the method and see if it gets hit?

2. Take a look at this:

HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
preferredTheme.Expires = DateTime.Now.AddMonths(3);
preferredTheme.Value = Themes.SelectedValue;

Session["MyMasterPage"] = Themes.SelectedValue;
After you set the cookie, you are redirecting the user away from the page. This means that the code that sets the session is never called. Remove the first call to Redirect and the session value will be set.

3. Why are you using cookies and Session state at the same time? Both seem to do the same (store the selected theme) so I would choose one or the another but not both.


Imar Spaanjaars
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!