Dynamic Themes : Themes « Theme Style « ASP.Net






Dynamic Themes


File: DynamicThemes.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicThemes.aspx.cs" Inherits="DynamicThemes" Theme="ProTheme"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="lstThemes" runat="server"></asp:ListBox><br />
        <br />
        <asp:Button ID="cmdApply" runat="server" Text="Apply Theme" OnClick="cmdApply_Click" />
        <asp:Button ID="cmdClear" runat="server" Text="Clear Theme" OnClick="cmdClear_Click" />
    </div>
    </form>
</body>
</html>


File: DynamicThemes.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class DynamicThemes : System.Web.UI.Page
{
     
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
      DirectoryInfo themeDir = new DirectoryInfo(Server.MapPath("App_Themes"));
      lstThemes.DataTextField = "Name";
      lstThemes.DataSource = themeDir.GetDirectories();
      lstThemes.DataBind();
    }
    }

  protected void Page_PreInit(object sender, EventArgs e)
  {
    if (Session["Theme"] == null)
    {
      Page.Theme = "";
    }
    else
    {
      Page.Theme = (string)Session["Theme"];
    }
  }

  protected void cmdApply_Click(object sender, EventArgs e)
  {
    Session["Theme"] = lstThemes.SelectedValue;
    Server.Transfer(Request.FilePath);

  }
    protected void cmdClear_Click(object sender, EventArgs e)
    {
        Session["Theme"] = "";
        Server.Transfer(Request.FilePath);
    }
}


File: ProTheme.skin


<asp:ListBox runat="server" ForeColor="Blue" BackColor="LightYellow" />
<asp:TextBox runat="server" ForeColor="Blue" BackColor="LightYellow" />
<asp:Button runat="server" ForeColor="Blue" BackColor="LightYellow" />

           
       








ThemesDynamic.zip( 1 k)

Related examples in the same category

1.Disable the Theme for a particular page by using the EnableTheming attribute with the <%@ Page %> directive.
2.Applying a theme application-wide from the Web.config file
3.Removing Themes from Web Pages
4.Enable theming for specific controls by EnableTheming property
5.Creating Your Own Themes
6.Creating a Skin
7..skin file takes precedence over styles applied to every HTML element
8.Having Your Themes Include Images
9.Defining Multiple Skin Options: SkinID
10.Assigning the Page's Theme Programmatically (VB / C#)
11.Assigning the server control's SkinID property programmatically (VB / C#)
12.Disabling theming for your custom controls (VB / C#)
13.Disabling theming for properties in your custom controls
14.Calendar Themes
15.Themes Image
16.Themes Setup
17.Themes With CSS
18.Your own theme
19.Themes template
20.Global Themes