后台动态加载文件代码:

  //假设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 文件,换肤方案的更多相关文章

  1. 文字添加响应事件,js动态加载CSS, js弹出DIV

    文字添加响应事件,js动态加载CSS, js弹出DIV <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...

  2. 动态加载css,js

    function dynamicLoadCss(url) { var head = document.getElementsByTagName('head')[0]; var link = docum ...

  3. js实用方法记录-js动态加载css、js脚本文件

    js实用方法记录-动态加载css/js 附送一个加载iframe,h5打开app代码 1. 动态加载js文件到head标签并执行回调 方法调用:dynamicLoadJs('http://www.yi ...

  4. 动态加载CSS,JS文件

    var Head = document.getElementsByTagName('head')[0],style = document.createElement('style'); //文件全部加 ...

  5. 用JavaScript动态加载CSS和JS文件

    本文转载自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/11/14/2248451.html 今天项目中需要用到动态加载 CSS 文件 ...

  6. JavaScript动态加载CSS和JS文件

    var dynamicLoading = { css: function(path){ if(!path || path.length === 0){ throw new Error('argumen ...

  7. 使用js加载器动态加载外部js、css文件

    let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.us ...

  8. [AngularJS] 使用AngularCSS动态加载CSS

    [AngularJS] 使用AngularCSS动态加载CSS 前言 使用AngularAMD动态加载Controller 使用AngularAMD动态加载Service 上列两篇文章里,介绍了如何如 ...

  9. 动态加载css方法实现和深入解析

    一.方法引用来源和应用  此动态加载css方法 loadCss,剥离自Sea.js,并做了进一步的优化(优化代码后续会进行分析).  因为公司项目需要用到懒加载来提高网站加载速度,所以将非首屏渲染必需 ...

随机推荐

  1. xcode 3.x版本中的Executables 到xcode 4.x中怎么找不到了?

    转自:http://zhidao.baidu.com/question/327868169.html 1 在Scheme处选择Edit Scheme 2 点击Run(Debug) 3 在Argumen ...

  2. 线程控制之线程和I/O

    http://www.cnblogs.com/nufangrensheng/p/3498723.html中介绍了pread和pwrite函数,这些函数在多线程环境下是非常有帮助的,因为进程中的所有线程 ...

  3. 对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)--转

    出处:http://blog.csdn.net/xxd851116/archive/2009/06/25/4296866.aspx [前面的话] 在网上经常看到有人对request.getSessio ...

  4. Cookie和Session(session过程和设置进程外session)

    cookie 和  session 的区别 cookie 是保存在客户端上的一种机制   而session 是保存在服务端的一种机制 cookie的理解: 打个简单的比方,一个人生病了去A医院看病,回 ...

  5. Frame Stacking 框架堆叠

    /* [题目来源]http://poj.org/problem?id=1128 [题目分析] 几张图片叠在一起,给出堆叠后的情况,要求出所有可能的从下到上的堆叠顺序. [思路分析] 1.题目已经很明确 ...

  6. Python 字典排序

    思路是把字典转为列表后再排序 d={'z':1,'y':2,'x':3} # 字典 s=d.items() # [('y', 2), ('x', 3), ('z', 1)] 列表 s.sort() # ...

  7. jquery 页面跳转 表单提交

    $("#button").click(function () {            $("#form").first().attr("action ...

  8. Fragment生命周期详解

    处理fragement的生命周期 管理fragment的生命周期有些像管理activity的生命周期.Fragment可以生存在三种状态: Resumed: Fragment在一个运行中的activi ...

  9. VM虚拟机下centos7 无法上网的问题解决办法

    博主本着学无止境的精神在虚拟机上安装了一个centos7 来敲敲命令行.刚开始就遇到了强大的阻力... ifconfig   vim  都没法用.这怎么行,安装呗.又学了圈安装,yum命令. 结果yu ...

  10. poj 2524 Ubiquitous Religions(宗教信仰)

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 30666   Accepted: ...