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. maven 配置

    四.eclipse配置maven eclipse---window---maven------User Settings: 之前设置的仓库的位置: 五.idea15配置maven idea14---s ...

  2. [解决方案] pythonchallenge level 1

    http://www.pythonchallenge.com/pc/def/map.html g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amk ...

  3. 使用 UnrealPak.exe 创建 Pak文件方法

    看来各位摸UE4 的基佬们,也是被DLC搞得不要不要的呢,其实热更新PAK是很简单就可以实现的,虽然当时我也是弄了快一个月. 下面贴一段以前在 Runtime 状态下 Mount Pak的代码,希望能 ...

  4. HDU5950(矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...

  5. linux crontab定时任务调用CI框架PHP代码

    *****监控项目中使用*****: sudo crontab -u wangyan -e i 5,25,45 * * * * wget http://xxx.xxx.com/xxx/xx Esc : ...

  6. Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key

    Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are ...

  7. 如何让iOS 保持界面流畅?这些技巧你知道吗

    如何让iOS 保持界面流畅?这些技巧你知道吗   作者:ibireme这篇文章会非常详细的分析 iOS 界面构建中的各种性能问题以及对应的解决思路,同时给出一个开源的微博列表实现,通过实际的代码展示如 ...

  8. 从指定的URL下载文件

    通过使用URLDownLoadToFile函数,我们能从指定的URL下载文件,保存到本地,并且下载的文件类型可以是可执行文件 实例如下,http://www.xuexic.com 的根目录下存在一个l ...

  9. 进入meta模式关闭背光灯

    1. 修改文件: mediatek/platform/mt6582/lk/boot_mode.c 2. 修改内容: boot_mode_select()函数: mt65xx_blacklight_of ...

  10. S2SH+mysql-软件开发实际部署问题-8个小时后提示MYSQL数据库无法连接

    type Exception report message description The server encountered an internal error () that prevented ...