主题和皮肤
1 组成元素 (1)主题文件.skin  (2)css文件 .css (3)图片和其他资源 .jpg
2 文件存储和组织形式 (1) 创建App_Themes 文件夹(只存存储文件夹及与主题有关的文件)
事例:
3 创建应用主题(名称mytheme)
  (1) 创建主题文件.skip 
   
主题和皮肤_html<asp:TextBox BackColor="Silver" ForeColor="Blue" Runat="Server" />
主题和皮肤_html<asp:BulletedList BulletStyle="CustomImage" BulletImageUrl="Images/arrow.gif" Runat="Server" />
  注意这里引用了图片 arrow.gif
  (2) 为主题添加css文件
主题和皮肤_htmlbody
主题和皮肤_动态加载_04主题和皮肤_动态加载_05{主题和皮肤_html_06}{
主题和皮肤_css_07    background-color: silver;
主题和皮肤_控件_08}
主题和皮肤_html
主题和皮肤_htmlA:link
主题和皮肤_动态加载_04主题和皮肤_动态加载_05{主题和皮肤_html_06}{
主题和皮肤_css_07    color: Blue;
主题和皮肤_css_07    text-decoration: underline;
主题和皮肤_控件_08}
主题和皮肤_htmlA:visited
主题和皮肤_动态加载_04主题和皮肤_动态加载_05{主题和皮肤_html_06}{
主题和皮肤_css_07    color: Blue;
主题和皮肤_css_07    text-decoration: underline;
主题和皮肤_控件_08}
主题和皮肤_htmlA:hover
主题和皮肤_动态加载_04主题和皮肤_动态加载_05{主题和皮肤_html_06}{
主题和皮肤_css_07    color: Red;
主题和皮肤_css_07    text-decoration: none;
主题和皮肤_控件_08}
主题和皮肤_htmlINPUT
主题和皮肤_动态加载_04主题和皮肤_动态加载_05{主题和皮肤_html_06}{
主题和皮肤_css_07    background-color: Orange;
主题和皮肤_控件_08}
主题和皮肤_html

(3)在aspx页面的第一行修改一下
主题和皮肤_html<%@ Page Language="C#" AutoEventWireup="true"   Theme ="mytheme"  CodeFile="Default1.aspx.cs" Inherits="test_skin_Default1" %>
(4)HTML代码部分应用如下:

主题和皮肤_html<fieldset style="width: 240px">
主题和皮肤_html                <legend>为主题添加CSS文件</legend>
主题和皮肤_html                <br />
主题和皮肤_html                使用CSS设置的HTML控件<br />
主题和皮肤_html                <br />
主题和皮肤_html                <a href="http://www.microsoft.com/china/" target="_blank">微软中国</a> <a href="http://www.microsoft.com/china/msdn/"
主题和皮肤_html                    target="_blank">中文MSDN</a><br />
主题和皮肤_html                <input type="text" /><br />
主题和皮肤_html                <br />
主题和皮肤_html                < <legend>在主题中使用图片</legend>
主题和皮肤_html                <asp:BulletedList ID="BulletedList1" runat="server" BulletStyle="CustomImage">
主题和皮肤_html                    <asp:ListItem Value="0">JSP程序设计</asp:ListItem>
主题和皮肤_html                    <asp:ListItem Value="1">计算机网络教程</asp:ListItem>
主题和皮肤_html                    <asp:ListItem Value="2">UML参考手册</asp:ListItem>
主题和皮肤_html                    <asp:ListItem Value="3">UML和模式应用</asp:ListItem>
主题和皮肤_html                </asp:BulletedList>                            
主题和皮肤_html               
主题和皮肤_html            </fieldset>
(5) 这样主题文件.skin 就应用到了页面
注: 为程序指定或禁用主题 在Web.Config文件里面
 
主题和皮肤_html            <system.web>
主题和皮肤_html        <pages theme="mytheme"></pages>
主题和皮肤_html        </system.web>
这样就不用在Html页面的第一行进行修改,可以进行直接应用

动态加载主题(skin文件):
(1)在主题下面新建2个主题,分别是Blue,Red
Blue主题下面建立主题文件Calendar.skin
主题和皮肤_html<asp:Calendar runat="server" BackColor="White" BorderColor="#EFE6F7"
主题和皮肤_html    CellPadding="4" DayNameFormat="Shortest" Font-Size="0.8em"
主题和皮肤_html    ForeColor="Black" Height="180px" Width="200px">
主题和皮肤_html    <SelectedDayStyle BackColor="#41519A" Font-Bold="True" ForeColor="White" Font-Size="0.8em"/>
主题和皮肤_html    <SelectorStyle BackColor="#41519A" Font-Size="0.8em"/>
主题和皮肤_html    <WeekendDayStyle BackColor="#99ACDD" Font-Size="0.8em"/>
主题和皮肤_html    <OtherMonthDayStyle ForeColor="#41519A" Font-Size="0.9em"/>
主题和皮肤_html    <TodayDayStyle BackColor="#B2C3E1" ForeColor="Black" Font-Size="0.8em"/>
主题和皮肤_html    <NextPrevStyle VerticalAlign="Bottom" Font-Bold="True" ForeColor="White" Font-Size="0.8em"/>
主题和皮肤_html    <DayHeaderStyle Font-Bold="True" Font-Size="0.8em" BackColor="#B2C3E1"/>
主题和皮肤_html    <TitleStyle BackColor="#41519A" BorderColor="Black" Font-Bold="True" ForeColor="White" Font-Size="0.9em"/>
主题和皮肤_html    <DayStyle Font-Size="0.8em" />
主题和皮肤_html</asp:Calendar>

Red 主题下面建立主题文件Calendar.skin
主题和皮肤_html<asp:Calendar runat="server" BackColor="White" BorderColor="#EFE6F7"
主题和皮肤_html    CellPadding="4" DayNameFormat="Shortest" Font-Size="0.8em"
主题和皮肤_html    ForeColor="Black" Height="180px" Width="200px">
主题和皮肤_html    <SelectedDayStyle BackColor="#8A170F" Font-Bold="True" ForeColor="White" Font-Size="0.8em"/>
主题和皮肤_html    <SelectorStyle BackColor="#8A170F" Font-Size="0.8em"/>
主题和皮肤_html    <WeekendDayStyle BackColor="#E7E7E7" Font-Size="0.8em"/>
主题和皮肤_html    <OtherMonthDayStyle ForeColor="#8A170F" Font-Size="0.9em"/>
主题和皮肤_html    <TodayDayStyle BackColor="#F4000A" ForeColor="White" Font-Size="0.8em" Font-Bold="True"/>
主题和皮肤_html    <NextPrevStyle VerticalAlign="Bottom" Font-Bold="True" ForeColor="White" Font-Size="0.8em"/>
主题和皮肤_html    <DayHeaderStyle Font-Bold="True" Font-Size="0.8em" BackColor="#F4000A" ForeColor="White"/>
主题和皮肤_html    <TitleStyle BackColor="#8A170F" BorderColor="Black" Font-Bold="True" ForeColor="White" Font-Size="0.9em"/>
主题和皮肤_html    <DayStyle Font-Size="0.8em" />
主题和皮肤_html</asp:Calendar>

(2)UI部分和后台代码如下:
主题和皮肤_动态加载_04主题和皮肤_动态加载_05<%主题和皮肤_html_06@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
主题和皮肤_html
主题和皮肤_动态加载_04主题和皮肤_动态加载_05<script runat="server">主题和皮肤_html_06
主题和皮肤_css_07    void Page_PreInit(Object sender, EventArgs e)
主题和皮肤_控件_94主题和皮肤_动态加载_95    主题和皮肤_html_06{
主题和皮肤_css_07        //设置页面所设置的主题
主题和皮肤_css_07        string theme="";
主题和皮肤_css_07        if (Request.QueryString["theme"] == null)
主题和皮肤_控件_94主题和皮肤_动态加载_95        主题和皮肤_html_06{
主题和皮肤_css_07            theme = "Red";
主题和皮肤_动态加载_104        }
主题和皮肤_css_07        else
主题和皮肤_控件_94主题和皮肤_动态加载_95        主题和皮肤_html_06{
主题和皮肤_css_07            theme = Request.QueryString["theme"];
主题和皮肤_动态加载_104        }
主题和皮肤_css_07        Page.Theme = theme;
主题和皮肤_css_07        //设置DropDownList控件的选中项
主题和皮肤_css_07        ListItem item = DropDownList1.Items.FindByValue(theme);
主题和皮肤_css_07        if (item != null)
主题和皮肤_控件_94主题和皮肤_动态加载_95        主题和皮肤_html_06{
主题和皮肤_css_07            item.Selected = true;
主题和皮肤_动态加载_104        }
主题和皮肤_动态加载_104    }
主题和皮肤_css_07    void SelectedIndexChanged(Object sender, EventArgs e)
主题和皮肤_控件_94主题和皮肤_动态加载_95    主题和皮肤_html_06{
主题和皮肤_css_07        //获取DropDownList选中项值,并进行页面重定向
主题和皮肤_css_07        string url = Request.Path + "?theme=" + DropDownList1.SelectedItem.Value;
主题和皮肤_css_07        Response.Redirect(url);
主题和皮肤_控件_08    }
主题和皮肤_html</script>
主题和皮肤_html
主题和皮肤_html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
主题和皮肤_html<html xmlns="http://www.w3.org/1999/xhtml">
主题和皮肤_html<head runat="server">
主题和皮肤_html    <title>示例6-5</title>
主题和皮肤_html</head>
主题和皮肤_html<body>
主题和皮肤_html    <form id="form1" runat="server">
主题和皮肤_html        <div>
主题和皮肤_html            <fieldset style="width: 210px">
主题和皮肤_html                <legend>动态加载主题</legend>
主题和皮肤_html                <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="SelectedIndexChanged"
主题和皮肤_html                    AutoPostBack="True">
主题和皮肤_html                    <asp:ListItem Value="Red">启用Red主题</asp:ListItem>
主题和皮肤_html                    <asp:ListItem Value="Blue">启用Blue主题</asp:ListItem>
主题和皮肤_html                </asp:DropDownList>
主题和皮肤_html                <br />
主题和皮肤_html                <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
主题和皮肤_html            </fieldset>
主题和皮肤_html        </div>
主题和皮肤_html    </form>
主题和皮肤_html</body>
主题和皮肤_html</html>
主题和皮肤_html
(3)这样就实现了一次简单的动态加载主题


注:  以上代码 需要在asp.net 2.0下面运行