My runtime error is:
The 'Theme' property can only be set in or before the 'Page_PreInit' event
After implimenting the c# code chapter 6 page 227. This occurs when the following event handler is put in place:
this.PreRender += newEventHandler(Page_PreInt);
If thats commented out it runs. Here is my offending BasePage class:
Code:
publicclassBasePage : System.Web.UI.Page
{
privatevoid Page_PreRender(object sender, EventArgs e)
{
if (this.Title == "" || this.Title == null || this.Title.Length == 0)
{
thrownewException("Page title cannot be an empty string.");
}
}
privatevoid Page_PreInt(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
Page.Theme = preferredTheme.Value;
}
}
public BasePage()
{
this.PreRender += newEventHandler(Page_PreRender);
this.PreRender += newEventHandler(Page_PreInt);
}
}
What have I done wrong?
TYIA