simple code to change theme on run time

Here is the most simple code to change the themes dynamically.
Here I am assuming that you have three themes named Red, Green and Blue, and you have three buttons named RedBtn, GreenBtn and BlueBtn to change theme on run time. I set Green as my initial theme.


protected void Page_PreInit(object sender, EventArgs e)
{

if((string)Session["Flag"]=="true")
Page.Theme =(string) Session["themeSelected"];

}


protected void RedBtn_Click(object sender, EventArgs e)
{

Session["Flag"] = "true";
Session["themeSelected"] = "Red";
Server.Transfer(Request.FilePath);
}
protected void GreenBtn_Click(object sender, EventArgs e)
{
Session["themeSelected"] = "Green";
Server.Transfer(Request.FilePath);
}
protected void BlueBtn_Click(object sender, EventArgs e)
{
Session["Flag"] = "true";
Session["themeSelected"] = "Blue";
Server.Transfer(Request.FilePath);

}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: