Changing the themes of page on Button Click

Sandhyab
Posted by Sandhyab under ASP.NET category on | Points: 40 | Views : 1023
<%@ Page Language="C#" AutoEventWireup="true" Theme="Green" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Button ID="btn1" runat="server" Text="Black" OnClick="Button1_Click" />
<asp:Button ID="Button1" runat="server" Text="Green" OnClick="Button2_Click" />
</div>
</form>
</body>
</html>


Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
public static string theme;
protected void Page_PreInit(object sender, EventArgs e)
{
switch (Request.QueryString["theme"])
{
case "Black":
Page.Theme = "Black";
break;
case "Green":
Page.Theme = "Green";
break;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?theme=Green");
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?theme=Black");
}
}



Make sure that You have themes with the names Green and Black

Comments or Responses

Login to post response