我遇到了这样的问题,请教google,结果大多数只是介绍那个注册js的几个函数,而这几个函数插入的js都在body里面,幸而在老外那里看到了这个代码,其实比较简单,但够有用:
HtmlGenericControl Include2 = new HtmlGenericControl("script");
Include2.Attributes.Add("type", "text/javascript");
Include2.InnerHtml = "alert('JavaScript in Page Header');";
this.Page.Header.Controls.Add(Include2);
Include2.Attributes.Add("type", "text/javascript");
Include2.InnerHtml = "alert('JavaScript in Page Header');";
this.Page.Header.Controls.Add(Include2);