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

it2022-05-09  22

在开发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里面。

转载于:https://www.cnblogs.com/nanshouyong326/archive/2008/10/17/1313420.html

相关资源:数据结构—成绩单生成器

最新回复(0)