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. mySQL基本操作学习笔记(一)

                                                                                                        ...

  2. 关于解析P D X P 协议的心得

    1一个线程进队Quee 一个线程出队 也应该lock,不然会出错. 2 委托的效率较低 能不用委托的地方,尽量不要用委托. 在一个线程中需要调用控件时采用委托. 3 for循环中异步发送数据不能保证发 ...

  3. 关于spring中无法将service注入到servlet中的问题

    首先,servlet是动态网页项目区别于普通的java项目的,是动态网页项目中web.xml主要配置文件管理的,而spring只能管理普通的pojo,而没办法直接注入,尽管你的注入方式和配置方式都没有 ...

  4. TypeScript 中的 "=>" 真的很好用!!!

    class funs { public $scope: IBarPadScope; constructor($scope: IBarPadScope) { this.$scope = $scope; ...

  5. linux命令:文件属性

    Linux 文件的属性主要包括:节点.种类.权限模式.链接数量.所归属的用户和用户组.文件大小.最近访问或修改的时间等内容. 命令: ls -lih 输出: [root@localhost test] ...

  6. 【物联网应用与维护】基于SQL sever 2008 R2的数据库定时处理

    --SQLServer : --1.打开[SQL Server Management Studio],在[对象资源管理器]列表中选择[SQL Server 代理]: --2.鼠标右击[SQL Serv ...

  7. MVC 知识点学习2

    1._Layout.cshtml   @RenderBody() 2.自定义扩展HtmlHelper(需要添加Bootstrap.js或者Bootstrap.min.js文件到项目中) namespa ...

  8. mvc3 上传图片

    这是在Control里使用的代码,是在后台管理需要上传图片时使用的,不过我在这犯了一个错误, Request.Files[inputName];inputName名字中的大小写<input ty ...

  9. C++学习笔记30:模板与型式参数化

    转型操作 接受目标型式作为模板参数 Programmer *p = dynamic_cast<Programmer*>(e) 模板工作原理 使用template<typename T ...

  10. 【css】a标签的用法

    <a>标签属性display的不同设置达到目的 display:block和display:inline; display:block 可以使得<a>标签设置宽高.边线.mar ...