.NET Web后台动态加载Css、JS 文件,换肤方案
后台动态加载文件代码:
//假设css文件:TestCss.css #region 动态加载css文件
public void AddCss()
{
HtmlGenericControl _CssFile = new HtmlGenericControl("link");
_CssFile.ID = "CssFile";
_CssFile.Attributes["rel"] = "stylesheet";
_CssFile.Attributes["type"] = "text/css";
_CssFile.Attributes["href"] = "/Styles/TestCss.css";
if (this.FindControl(_CssFile.ID) == null)
{
this.Page.Header.Controls.Add(_CssFile);
}
} #endregion 动态加载css文件
换肤方案
1) 写个类(Page_Parent.cs) 动态加载样式文件
2) 所有页面继承Page_Parent.cs类
Page_Parent.cs类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.HtmlControls; namespace Test
{
public class Page_Parent: System.Web.UI.Page
{ public Page_Parent()
{
this.Load += Page_Parent_Load;
this.Error += Page_Parent_Error;
}
/// <summary>
/// 捕捉未处理的页面错误
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Page_Parent_Error(object sender, EventArgs e)
{
throw new NotImplementedException();
} private void Page_Parent_Load(object sender, EventArgs e)
{
AddCss();
} //假设css文件:TestCss.css #region 动态加载css文件
public void AddCss()
{
HtmlGenericControl _CssFile = new HtmlGenericControl("link");
_CssFile.ID = "CssFile";
_CssFile.Attributes["rel"] = "stylesheet";
_CssFile.Attributes["type"] = "text/css";
_CssFile.Attributes["href"] = "/Styles/TestCss.css";
if (this.FindControl(_CssFile.ID) == null)
{
this.Page.Header.Controls.Add(_CssFile);
}
} #endregion 动态加载css文件
}
}
测试页面Web_Test.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Web_Test.aspx.cs" Inherits="Web.Web_Test" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>1232131</p>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace Web
{
public partial class Web_Test : Page_Parent
{
protected void Page_Load(object sender, EventArgs e)
{ }
}
}
.NET Web后台动态加载Css、JS 文件,换肤方案的更多相关文章
- 文字添加响应事件,js动态加载CSS, js弹出DIV
文字添加响应事件,js动态加载CSS, js弹出DIV <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...
- 动态加载css,js
function dynamicLoadCss(url) { var head = document.getElementsByTagName('head')[0]; var link = docum ...
- js实用方法记录-js动态加载css、js脚本文件
js实用方法记录-动态加载css/js 附送一个加载iframe,h5打开app代码 1. 动态加载js文件到head标签并执行回调 方法调用:dynamicLoadJs('http://www.yi ...
- 动态加载CSS,JS文件
var Head = document.getElementsByTagName('head')[0],style = document.createElement('style'); //文件全部加 ...
- 用JavaScript动态加载CSS和JS文件
本文转载自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/11/14/2248451.html 今天项目中需要用到动态加载 CSS 文件 ...
- JavaScript动态加载CSS和JS文件
var dynamicLoading = { css: function(path){ if(!path || path.length === 0){ throw new Error('argumen ...
- 使用js加载器动态加载外部js、css文件
let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.us ...
- [AngularJS] 使用AngularCSS动态加载CSS
[AngularJS] 使用AngularCSS动态加载CSS 前言 使用AngularAMD动态加载Controller 使用AngularAMD动态加载Service 上列两篇文章里,介绍了如何如 ...
- 动态加载css方法实现和深入解析
一.方法引用来源和应用 此动态加载css方法 loadCss,剥离自Sea.js,并做了进一步的优化(优化代码后续会进行分析). 因为公司项目需要用到懒加载来提高网站加载速度,所以将非首屏渲染必需 ...
随机推荐
- Seconds_Behind_Master
http://blog.chinaunix.net/uid-28212952-id-3494560.html 今天同事遇到一个故障,xtrabackup备份中flush tables with rea ...
- DDNS 的工作原理及其在 Linux 上的实现--转
http://www.ibm.com/developerworks/cn/linux/1305_wanghz_ddns/index.html DDNS (Dynamic DNS) 扩展了 DNS 将客 ...
- Face The Right Way
Face The Right Way Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2564 Accepted: 117 ...
- How to Diagnose Audi Vehicles via Tuirel S777
Here share how to diagnose Audi cars via Tuirel S777. 1.Well connect Tuirel S777 to your Audi car, a ...
- 查看Oracle执行计划的几种方法
查看Oracle执行计划的几种方法 一.通过PL/SQL Dev工具 1.直接File->New->Explain Plan Window,在窗口中执行sql可以查看计划结果.其中,Cos ...
- 开发一个struts2的实例
前面一篇博客(实现struts2框架)带大家对基于mvc业务流程熟悉了一下,现在我们就用对mvc实现最好的框架struts2来开发一个应用实例.虽然现在MyEclipse8.5以上版本已经开始支持St ...
- linux 文件夹权限及umask
先创建一个目录,看看权限: $ ll 总用量 drwxrwxr-x huangxm huangxm 2月 : ./ drwxr-xr-x huangxm huangxm 2月 : ../ drwxrw ...
- Linux串口编程(转载)
在嵌入式Linux中,串口是一个字设备,访问具体的串行端口的编程与读/写文件 的操作类似,只需打开相应的设备文件即可操作.串口编程特殊在于串 口通信时相关参数与属性的设置.嵌入式Linux的串口编程时 ...
- 为什么Java byte 类型的取值范围是-128~127 (转)
概念:负数的补码是该 数 绝 对 值 的 原 码 按 位 取 反 ,然 后 对 整个数 加 1 步骤: 1.确定byte是1个字节,也就是8位 2.最大的应该是0111 1111,因为第一位是符号位, ...
- cent0s7 显卡驱动导致重启黑屏
由于 CentOS7.0 版本与前面的 CentOS6.5 及之前的版本的模式变更方法有很大 的不同,以前的版本中我们可以在vi /etc/inittab 文件中将id:5:initdefault 更 ...