044. asp.net主题之三应用或禁用主题和动态加载主题
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主题之三应用或禁用主题和动态加载主题的更多相关文章
- WPF 动态加载主题由zip
经典主题的方式 主题战略 加载速度 本机支持 (不需要额外的代码) 支持代码为主题 (捆绑代码 & 资源成单独的文件) 支持资源层次结构中导航 动态加载 动态卸载 轻松地编辑和编译 (不需要安 ...
- 044. asp.net主题之二为主题添加CSS样式和动态加载主题
1. 新建任意一个网站, 默认主页为Default.aspx, 增加一个App_Themes目录, 用于存储主题, 添加一个MyTheme的主题, 在MyTheme主题下添加一个样式表文件, 默认名称 ...
- 主攻ASP.NET MVC4.0之重生:上下滑动屏幕动态加载数据
@{ ViewBag.Title = "Index"; } <!DOCTYPE html> <html> <head> ...
- ASP.NET加载主题和皮肤样式的各种方式
一.加载主题(皮肤.样式表)的多种方式 除了在页面指令中采用Theme或者StylesheetTheme为单个页面加载主题外,还可以通过配置文件为多个页面批量加载主题,另外,还可以通过改变页面的The ...
- 从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用
标题:从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用. 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p/1171 ...
- 在ASP.NET中动态加载内容(用户控件和模板)
在ASP.NET中动态加载内容(用户控件和模板) 要点: 1. 使用Page.ParseControl 2. 使用base.LoadControl 第一部分:加载模板 下 面是一个模板“<tab ...
- asp.net动态加载ascx用户控件
原文:asp.net动态加载ascx用户控件 在主aspx/ascx文件中,将目标ascx1,ascx2控件拖拉到其页面中,然后删除,目的是要生成:Register 代码,然后在主文件中定义DIV或T ...
- Asp.Net Core 项目实战之权限管理系统(8) 功能菜单的动态加载
0 Asp.Net Core 项目实战之权限管理系统(0) 无中生有 1 Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端 2 Asp.Net Core 项目实战之 ...
- ASP.NET MVC动态加载数据
ASP.NET MVC动态加载数据,一般的做法是使用$.each方法来循环产生tabel: 你可以在html时先写下非动态的部分: Source Code 上图中,有一行代码: <tbody ...
随机推荐
- Axis2测试webservice server以及client
一.环境搭建 下载axis2-1.6.2-war.zip/axis2-1.6.2-bin.zip等. 参考axis2-1.6.2-war\README.txt以及axis2-1.6.2-war\axi ...
- 使用Excel 2007绘制甘特图
本文将教大家如何使用Excel 2007制作甘特图.Excel并未提供甘特图类型,但还是可以绘制甘特图的,方法就是通过对堆积条形图类型进行自定义,使之显示任务.任务工期和层次结构. 下面的过程可帮助创 ...
- lumia520刷机注意事项
1.下载后的固件名称中设备名前的随机字符都要去掉 2.安装完nokia care suit后最好在driver目录下重新双击安装usb driver
- 深入浅出REST
不知你是否意识到,围绕着什么才是实现异构的应用到应用通信的“正确”方式,一场争论正进行的如火如荼:虽然当前主流的方式明显地集中在基于SOAP.WSDL和WS-*规范的Web Services领域,但也 ...
- JMS links
http://yuxisanren.iteye.com/blog/1912587 http://somebody-hjh.iteye.com/blog/726050 http://docs.oracl ...
- Cruehead.1
查壳 没有 我拖 alt+F9 到上面 入口处 下断 关键跳 略过 就没了 要实现 强暴 直接过... 仔细来看看... 那两个调用 都下断 看看 判断 ...
- 黑马-----内存模型和volatile详解
黑马程序员:Java培训.Android培训.iOS培训..Net培训 JAVA线程-内存模型和volatile详解 一.单核内存模型 1.程序运行时,将临时数据存放到Cache中 2.将CPU计算所 ...
- SFTP交互式文件传输
sftp 是一个交互式文件传输程式.它类似于 ftp, 但它进行加密传输,比FTP有更高的安全性.下边就简单介绍一下如何远程连接主机,进行文件的上传和下载,以及一些相关操作. 举例,如远程主机的 IP ...
- Qt线程(4) 降低线程占用CPU
问题描述: 一般将计算量大的处理过程单独放置到一个单独的线程处理,因此很有可能你的处理过程需要while(1)或类似的操作. 也因此很有可能造成线程在处理时计算机CPU占用过高的情况. 解决办法: 降 ...
- c#关于日期的两个知识点
1 C#中如何获得两个日期之间的天数差 DateTime d1;DateTime d2; int days = (d1 - d2).Days;//天数差 2 C#中从字符串得到DateTimeConv ...