Changing the themes of page on Button Click

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<form id="form1" runat="server">

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

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";
case "Green":
Page.Theme = "Green";
protected void Button1_Click(object sender, EventArgs e)
protected void Button2_Click(object sender, EventArgs e)

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

Comments or Responses

Login to post response