1.向项目中添加Jscript文件
1
//script1.js-----
2
function doClick1()
3
{
4
alert("OK");
5
}

2

3

4

5

2.解决方案资源管理器中,右键查看script_1.js的属性,把高级中的“生成操作”属性设置成“嵌入的资源”。
3.向AssemblyInfo.cs文件中添加如下行注意名称: 名称= 程序集名 + 目录名 + 文件名, yj.WebControl.ClientScriptResourceTest.script1.js 为名称)
[assembly: System.Web.UI.WebResource("yj.WebControl.ClientScriptResourceTest.script1.js", "application/x-javascript")]
4.向项目中添加一个类, 实例:
1
using System;
2
using System.Drawing;
3
using System.Web.UI;
4
using System.Web;
5
using System.Globalization;
6
namespace yj.WebControl
7
{
8
public class ClientScriptResourceTest : Control
9
{
10
//调用脚本资源
11
protected override void OnLoad(EventArgs e)
12
{
13
if (this.Page != null)
14
{
15
this.Page.ClientScript.RegisterClientScriptResource(typeof(ClientScriptResourceTest),
16
"yj.WebControl.ClientScriptResourceTest.script1.js");
17
}
18
19
base.OnLoad(e);
20
}
21
}
22
}
23

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23
