Search code examples
asp.netthemesskin

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


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


Solution

  • 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;
        }
    }