NibblyPig
NibblyPig

Reputation: 52942

How do I put a theme chooser on my master page?

I put a drop down box on my master page with hardocoded theme values, and called it lstThemeChooser.

I want to be able to set the page theme using it. I read that I should put this in each of my pages:

protected void Page_PreInit(object sender, EventArgs e)
{
    Page.Theme = Request["lstThemeChooser"];
}

However the Request is null, so no theme is set.

The drop down box is set to autopostback=True.

Any ideas what I am doing wrong, or if this is somehow completely impossible?

(asp.net)

Upvotes: 0

Views: 609

Answers (1)

Arthur
Arthur

Reputation: 8129

You cannot do that in your Masterpage. You have to do that in all of your Pages. I would suggest sub classing the Page Object:

namespace MyNamespace.Mycontrols 
{
    public class Page : System.Web.UI.Page
    {
        public Page()
        {
            this.PreInit += new EventHandler(Page_PreInit);
        }

        void Page_PreInit(object sender, EventArgs e)
        {
            // Apply Theme
            this.Theme = Request["lstThemeChooser"];
        }
    }
}

EDIT: Using that class

public partial class MyPage: MyNamespace.Mycontrols.Page
{
    ...
}

Upvotes: 1

Related Questions