js| Compilation | news | links
1. Add a JScript file to your project
Script_1.js-----
function DoClick1 ()
{
Alert ("Ok1_wufeng");
}
Script_2.js-----
function DoClick2 ()
{
Alert ("OK2");
}
2. In Solution Explorer, right-click the properties of Script_1.js and Script_2.js and set the Build Action property in advanced to "embedded resources."
3. Add the following line to the AssemblyInfo.cs file: (Note the domain name WF.) ClientScriptResourceLabel)
[Assembly:System.Web.UI.WebResource ("WF.") ClientScriptResourceLabel.script_1.js "," Application/x-javascript ")]
[Assembly:System.Web.UI.WebResource ("WF.") ClientScriptResourceLabel.script_2.js "," Application/x-javascript ")]
4. Add a class to the project, instance:
Using System;
Using System.Drawing;
Using System.Web.UI;
Using System.Web;
Using System.Globalization;
namespace WF. ClientScriptResourceLabel
{
public class ClientScriptResourceLabel:System.Web.UI.WebControls.WebControl
{
Invoke Script Resource
protected override void OnPreRender (EventArgs e)
{
if (this. Page!= null)
{
This. Page.ClientScript.RegisterClientScriptResource (typeof (ClientScriptResourceLabel), "WF." ClientScriptResourceLabel.script_1.js ");
This. Page.ClientScript.RegisterClientScriptResource (typeof (ClientScriptResourceLabel), "WF." ClientScriptResourceLabel.script_2.js ");
}
Base. OnPreRender (e);
}
<summary>
Methods to render the control rendercontents
</summary>
protected override void RenderContents (HtmlTextWriter output)
{
Output. AddAttribute ("id", "1");
Output. AddAttribute ("Type", "checkbox");
Output. AddAttribute ("Value", "Test 1");
Output. AddAttribute ("onclick", "javascript:doclick1 ();");
Output. RenderBeginTag (Htmltextwritertag.input);
Output. RenderEndTag ();
Output. AddAttribute ("id", "2");
Output. AddAttribute ("Type", "checkbox");
Output. AddAttribute ("Value", "Test 2");
Output. AddAttribute ("onclick", "Javascript:doclick2 ();");
Output. RenderBeginTag (Htmltextwritertag.input);
Output. RenderEndTag ();
Base. RenderContents (output);
}
}
}