Themes/Dynamic.aspx <%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Dynamic.aspx.cs" Inherits="Themes_Dynamic" Title="主题测试-动态加载主题" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <p> 相关.skin文件内容如下:<asp:Image runat="server" ImageUrl="Images/pic.jpg" /> </p> <p> <a href="?theme=blue">蓝色主题</a> <a href="?theme=red">红色主题</a> </p> <p> 该Image控件应用主题中的样式,包括ImageUrl <br /> <asp:Image ID="img" runat="server" /> </p> </asp:Content> Themes/Dynamic.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; public partial class Themes_Dynamic : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Page_PreInit(object sender, System.EventArgs e) { // 动态修改Page的Theme要在Page_PreInit方法中实现 if (!String.IsNullOrEmpty(Request.QueryString["theme"])) { Page.Theme = Request.QueryString["theme"]; } else { Page.Theme = "blue"; } } }