title: Change website theme dynamically via buttons
body: <p>I've been learning a bit of asp.net and I've been having issues with the whole dynamic theme change, I've been following a book that teaches how to do it via a drop down menu, but I wanted to challenge myself and do it with buttons.</p>
  
  <p>My website has 2 themes and therefore, two buttons that represent each theme (orangefresh and greenfresh), this is my master page code behind:</p>
  
  <pre><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 mpage : System.Web.UI.MasterPage
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!Page.IsPostBack)
          {
              string selectedTheme = Page.Theme;
              HttpCookie webtheme = Request.Cookies.Get("webtheme");
              if (webtheme != null)
              {
                  selectedTheme = webtheme.Value;
              }
  
          }
      }
      protected void orangefresh_Click(object sender, EventArgs e)
      {
          HttpCookie webtheme = new HttpCookie("webtheme");
          webtheme.Expires = DateTime.Now.AddMonths(3);
          webtheme.Value = "orangefresh";
          Response.Cookies.Add(webtheme);
          Response.Redirect(Request.Url.ToString());
      }
  
      protected void greenfresh_Click(object sender, EventArgs e)
      {
          HttpCookie webtheme = new HttpCookie("webtheme");
          webtheme.Expires = DateTime.Now.AddMonths(3);
          webtheme.Value = "greenfresh";
          Response.Cookies.Add(webtheme);
          Response.Redirect(Request.Url.ToString());
      }
  }
  </code></pre>
  
  <p>And this is my Base Page:</p>
  
  <pre><code>using System;
  using System.Web;
  public class BasePage : System.Web.UI.Page
  {
  private void Page_PreInit(object sender, EventArgs e)
  {
  HttpCookie webtheme = Request.Cookies.Get("webtheme");
  if (webtheme != null)
  {
      Page.Theme = webtheme.Value;
  }
  }
  public BasePage()
  {
      this.PreInit += new EventHandler(Page_PreInit);
  }
  }
  </code></pre>
  
  <p>Seeing as I have no experience with cookies, I decided to look at the code from the beginning, I tested out if the Click event was storing a value on the cookie, I created a Label on the website and gave it's .Text property the cookie's .Value, nothing happened. So I started to remove code to see what was stopping the event, and I found that this line...</p>
  
  <pre><code> Response.Redirect(Request.Url.ToString());
  </code></pre>
  
  <p>... was responsible for it. Just for the sake of it, I removed that one line and tested my website again, still, no changes in the theme.</p>
  
  <p>Any help would be appreciated.</p>