1.为单个页面指定主题可以将@Page指令的Theme或StyleSheetTheme属性设置为要使用的主题名称, 代码如下:

<%@ Page  Theme ="MyTheme" %>

<%@ Page  StyleSheetTheme="MyTheme" %>

StyleSheetTheme属性的工作方式与普通主题(使用Theme设置的主题)类似, 不同的是当使用StyleSheetTheme时, 控件外观的设置可以被页面中声明的同一类型的相同属性所代替. 例如: 如果使用Theme属性指定主题, 该主题指定所有的Button控件的背景都是黄色, 那么即使在页面中个别Button控件的背景色设置了不同颜色, 页面中所有的Button控件的背景依然是黄色. 如果需要改变个别Button的背景色, 则需要使用StyleSheetTheme属性指定主题.

禁用打个页面的主题, 只需要将@Page指令的EnableTheming属性设置为False即可. 代码如下:

<%@ Page  EnableTheming ="False" %>

如果想要禁用控件的主题, 只要将控件的EnableTheming属性设置为False即可, 比如想要禁用Button的主题, 代码如下:

 <asp:Button ID="Button1" runat="server" EnableTheming="false" Text="Button" />

2. 为应用程序指定和禁用主题:

为了快速地位整个网站的所有页面设置相同的主题, 可以设置Web.config文件中的<pages>配置节点中的内容. Web.config文件的配置代码如下:

<configuration>
<connectionStrings/>
<system.web>
<pages theme="ThemeName"></pages>
<!--或者<pages styleSheetTheme="ThemeName" ></pages>-->
</system.web>
</configuration>

若要禁用整个应用程序的主题设置, 只要将<pages>配置节中的Theme属性或者StyleSheetTheme属性设置为空即可;

下面演示一个动态加载主题的示例:

整体文件列表

Default.aspx文件内容:

<%@ Page Language="C#" AutoEventWireup="true"  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 id="Head1" runat="server">
<title>动态加载主题</title>
</head>
<body>
<form id="form1" runat="server">
<div>
动态加载主题<br />
<table>
<tr>
<td style="width: 100px">
选择主题:</td>
<td style="width: 100px">
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="Theme1">主题一</asp:ListItem>
<asp:ListItem Value="Theme2">主题二</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 100px">
<a href ="default.aspx">返回</a>
</td>
</tr>
<tr>
<td style="width: 100px">
默认外观:</td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
命名外观:</td>
<td style="width: 100px">
<asp:TextBox SkinID="textboxSkin" ID="TextBox2" runat="server" ></asp:TextBox></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<input id="Button1" type="button" value="button" /></td>
<td style="width: 100px">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Default.aspx.cs文件内容:

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
//切换主题的时候触发下拉列表的选择项改变事件
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string url = Request.Path + "?theme=" + DropDownList1.SelectedItem.Value;
Response.Redirect(url);
}
//注意使用Theme属性指定页面的主题, 只能在页面的PreInit事件发生之前或者发生过程中设置, 当前示例是在发生过程中修改Page对象的Theme属性,达到修改主题的目的
void Page_PreInit(Object sender, EventArgs e)
{
string theme = "Theme1";
if (Request.QueryString["theme"] == null)
{
theme = "Theme1";
}
else
{
theme = Request.QueryString["theme"];
}
Page.Theme = theme;
ListItem item = DropDownList1.Items.FindByValue(theme);
if (item != null)
{
item.Selected = true;
}
}
}

Theme1下StyleSheet.css文件内容:

body
{
text-align :center;
color :Yellow ;
background-color :Navy;
}
A:link
{
color:White ;
text-decoration:underline;
}
A:visited
{
color:White;
text-decoration:underline;
}
A:hover
{
color :Fuchsia;
text-decoration:underline;
font-style :italic ;
}
input
{
border-color :Yellow;
}

Theme1下TextBoxSkin.skin文件内容:

<asp:TextBox runat="server" Text="主题1" BackColor="#FFE0C0" BorderColor="#FFC080" Font-Size="12pt" ForeColor="#C04000" Width="149px"/>
<asp:TextBox SkinId="textboxSkin" runat="server" Text="主题1" BackColor="#FFFFC0" BorderColor="Olive" BorderStyle="Dashed" Font-Size="15pt" Width="224px"/>

Theme2下StyleSheet.css文件内容:

body
{
text-align :center;
color :#004000;
background-color :Aqua;
}
A:link
{
color:Blue;
text-decoration:underline;
}
A:visited
{
color:Blue;
text-decoration:underline;
}
A:hover
{
color :Silver;
text-decoration:underline;
font-style :italic ;
}
input
{
border-color :#004040;
}

Theme2下TextBoxSkin.skin文件内容:

<asp:TextBox runat="server" Text="主题2" BackColor="#C0FFC0" BorderColor="#00C000" ForeColor="#004000" Font-Size="12pt" Width="149px"/>
<asp:TextBox SkinId="textboxSkin" runat="server" Text="主题2" BackColor="#00C000" BorderColor="#004000" ForeColor="#C0FFC0" BorderStyle="Dashed" Font-Size="15pt" Width="224px"/>

最终效果图:

044. asp.net主题之三应用或禁用主题和动态加载主题的更多相关文章

  1. WPF 动态加载主题由zip

    经典主题的方式 主题战略 加载速度 本机支持 (不需要额外的代码) 支持代码为主题 (捆绑代码 & 资源成单独的文件) 支持资源层次结构中导航 动态加载 动态卸载 轻松地编辑和编译 (不需要安 ...

  2. 044. asp.net主题之二为主题添加CSS样式和动态加载主题

    1. 新建任意一个网站, 默认主页为Default.aspx, 增加一个App_Themes目录, 用于存储主题, 添加一个MyTheme的主题, 在MyTheme主题下添加一个样式表文件, 默认名称 ...

  3. 主攻ASP.NET MVC4.0之重生:上下滑动屏幕动态加载数据

                @{ ViewBag.Title = "Index"; } <!DOCTYPE html> <html> <head> ...

  4. ASP.NET加载主题和皮肤样式的各种方式

    一.加载主题(皮肤.样式表)的多种方式 除了在页面指令中采用Theme或者StylesheetTheme为单个页面加载主题外,还可以通过配置文件为多个页面批量加载主题,另外,还可以通过改变页面的The ...

  5. 从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用

    标题:从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用. 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p/1171 ...

  6. 在ASP.NET中动态加载内容(用户控件和模板)

    在ASP.NET中动态加载内容(用户控件和模板) 要点: 1. 使用Page.ParseControl 2. 使用base.LoadControl 第一部分:加载模板 下 面是一个模板“<tab ...

  7. asp.net动态加载ascx用户控件

    原文:asp.net动态加载ascx用户控件 在主aspx/ascx文件中,将目标ascx1,ascx2控件拖拉到其页面中,然后删除,目的是要生成:Register 代码,然后在主文件中定义DIV或T ...

  8. Asp.Net Core 项目实战之权限管理系统(8) 功能菜单的动态加载

    0 Asp.Net Core 项目实战之权限管理系统(0) 无中生有 1 Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端 2 Asp.Net Core 项目实战之 ...

  9. ASP.NET MVC动态加载数据

    ASP.NET MVC动态加载数据,一般的做法是使用$.each方法来循环产生tabel: 你可以在html时先写下非动态的部分:  Source Code 上图中,有一行代码: <tbody ...

随机推荐

  1. Myeclipse闪退故障

    Myeclipse在编辑代码是出现反复一个异常错误. Index out of bounds,而且窗口关闭后还是出现, 于是在任务管理器里强制关闭MyEclipse. 关闭后启动MyEclipse总是 ...

  2. 用递归法判断字符串A中包含多少个字符串B

    string类提供了判断字符串B在字符串A中首次(或最后)出现的Index的方法,但有时候需要判断B在A中出现了多少次. 为此想了一个算法. public static void CountIndex ...

  3. C++深拷贝与浅拷贝

    当用一个已初始化过了的自定义类类型对象去初始化另一个新构造的对象的时候,拷贝构造函数就会被自动调用.也就是说,当类的对象需要拷贝时,拷贝构造函数将会被调用.以下情况都会调用拷贝构造函数: (1)一个对 ...

  4. 数据结构与算法分析-AVL树

    1.AVL树是带有平衡条件的二叉查找树. 2.AVL树的每个节点高度最多相差1. 3.AVL树实现的难点在于插入或删除操作.由于插入和删除都有可能破坏AVL树高度最多相差1的特性,所以当特性被破坏时需 ...

  5. Foundation

    类:NSObject .NSString.NSMutableString.NSNumber.NSValue.NSDate.NSDateFormatter.NSRange.Collections:NSS ...

  6. 麦克斯韦方程组 (Maxwell's equation)的简单解释

    [转载请注明出处]http://www.cnblogs.com/mashiqi 2016/12/12 以下会用高中的物理知识和大学微积分的数学知识对麦克斯韦方程组进行一个简单的解释.希望大家都能看得懂 ...

  7. 在 Java 代码中对 Kerberos 主体进行身份验证

    转载请注明出处:http://www.cnblogs.com/xiaodf/ 本文举例说明如何使用 org.apache.hadoop.security.UserGroupInformation 类在 ...

  8. C++构造函数与虚表覆盖

    在涉及到虚函数的情况下,C++构造函数的构造顺序为:先调用构造函数,虚表指针初始化,用户代码:如涉及到多重继承情况,初始化顺序为基类.子类(从左至右),假设一个类的继承情况如下图,其初始化顺序为:Po ...

  9. git命令大全

    git init                          # 初始化本地git仓库(创建新仓库)git config --global user.name "xxx"   ...

  10. python向数据库插入数据时出现乱码解决方案

    中文字符串前面加u 如: title =u"你好" contents = "m" ids="13" cur.execute("IN ...