当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

动态引入js文件和css样式表文件

责任编辑:nancy作者:ITPUB论坛   2008-07-07   
文本Tag: 微软 sql

【IT168技术文档】

  在开发web项目的过程中,总会碰到用户控件 .ascx 和页面,或者页面和母版页的很多关系。用局部的页面

  动态地给母版页引入js文件或者样式表文件,或者在用户控件里面根据需要动态引入js文件和样式表会比较好。

  以下是我引入的一个方法:
// 引入js文件 HtmlGenericControl scriptControl = new HtmlGenericControl("script"); scriptControl.Attributes.Add("type", "text/javascript"); scriptControl.Attributes.Add("language", "JavaScript"); scriptControl.Attributes.Add("src", "http://images.dayoo.com/travel/9208.files/changeimg.js"); Page.Header.Controls.Add(scriptControl); // 引入样式表 Literal cssControl = new Literal(); cssControl.Text = "<link href=\"http://images.dayoo.com/photo/17358.files/css.css\" rel=\"stylesheet\" type=\"text/css\"/>"; Page.Header.Controls.Add(cssControl);
  以上代码在页面或者控件的PageLoad里面。
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-07-07/200807071615659.shtml
技术开发相关文章  
  • 暂无
友情推介