内嵌js文件引用例子:
[assembly: WebResource(MyControl.SetupJs, "text/javascript")]
public class MyControl : WebControl
{
public const string SetupJs = "setupcontrol.js";
protected override void OnPreRender(EventArgs e)
{
Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "Setup", Page.ClientScript.GetWebResourceUrl(this.GetType(), SetupJs));
}
}
注意js文件要设为内嵌资源,如果有命名空间则SetupJs要相应地加上命名空间,假如你命名空间是Proejct.Controls,js文件又放在Resource文件夹内,则public const string SetupJs = "Project.Controls.Resource.setupcontrol.js"
非内嵌式:
public class MyControl : WebControl
{
protected override void OnPreRender(EventArgs e)
{
Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "Setup", your_url);
}
}
代码是从以前做的控件复制出来的,没有另外测试。