How to change theme of a total ASP.NET application dynamically?

Afshar Mohebi picture Afshar Mohebi · Jun 23, 2010 · Viewed 8.3k times · Source

Imagine an ASP.NET application with several theme defined within it. How can I change theme of total application (not just a single page) dynamically. I know it is possible through <pages Theme="Themename" /> in web.config. But I want to be able to change it dynamically. How shpuld I do it?

Thanks in Advance

Answer

Druid picture Druid · Jun 23, 2010

You can do this on Page_PreInit as explained here:

protected void Page_PreInit(object sender, EventArgs e)
{
    switch (Request.QueryString["theme"])
    {
        case "Blue":
            Page.Theme = "BlueTheme";
            break;
        case "Pink":
            Page.Theme = "PinkTheme";
            break;
    }
}