在页面的Header标签中加入javascript
2010-05-25 22:45 2323 阅读(593) 评论(0) 编辑 收藏 举报
代码在VS2010中通过
1. 加入js代码:方法如下:
HtmlGenericControl jsControl = new HtmlGenericControl(); jsControl.TagName = "script"; jsControl.Attributes.Add("type","text/javascript"); jsControl.InnerHtml = "alert(\"Header标签中js代²码\")"; Page.Header.Controls.Add(jsControl);
2.加入js文件
HtmlGenericControl jsRefControl = new HtmlGenericControl(); jsRefControl.TagName = "script"; jsRefControl.Attributes.Add("type", "text/javascript"); jsRefControl.Attributes.Add("src", "test.js"); Page.Header.Controls.Add(jsRefControl);