Chapter 2 ThemeSelector - Puzzled
I wrote the top code for the themeselector in the basepage and the themeselector did not work, however i copied the code from the chapter2 download and replaced the code completely and the themeselector worked. my question is that for the life of me I have no idea of any difference between the code. it is the same fricken thing except mine does not work and the one i copied does. my code is the top code and the code i copied is beneath it. any ideas would be appreciated thanks.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace MB.TheBeerHouse.UI
{
public class BasePage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
string id = Globals.ThemesSelectorID;
if (id.Length > 0)
{
// if this is a postback caused by the theme selector's dropdownlist,
// retrieve the selected theme and use it for the current page request
// && !string.IsNullOrEmpty(this.Request.Form[id])
if (this.Request.Form["_EVENTTARGET"] == id && !string.IsNullOrEmpty(this.Request.Form[id]))
{
this.Theme = this.Request.Form[id];
this.Session["CurrentTheme"] = this.Theme;
}
else
{
// if not a postback, or it is a postback cause by a control other than
// the theme selector, set the page's theme with the value that is in the
// session variable, if that variable is present
if (this.Session["CurrentTheme"] != null)
this.Theme = this.Session["CurrentTheme"].ToString();
//this.Theme = "PlainHtmlYellow";
}
}
base.OnPreInit(e);
}
}
}
my code on top the copied code is below
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace MB.TheBeerHouse.UI
{
public class BasePage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
string id = Globals.ThemesSelectorID;
if (id.Length > 0)
{
// if this is a postback caused by the theme selectors dropdownlist,
// retrieve the selected theme and unse it for the current page request
if (this.Request.Form["__EVENTTARGET"] == id && !string.IsNullOrEmpty(this.Request.Form[id]))
{
this.Theme = this.Request.Form[id];
this.Session["CurrentTheme"] = this.Theme;
}
else
{
if (this.Session["CurrentTheme"] != null)
this.Theme = this.Session["CurrentTheme"].ToString();
}
}
base.OnPreInit(e);
}
}
}
|