JavaScript: Compile js files into dynamic link library (dll) files. Javascript tutorial
1. Add a Jscript file to the Project
// Script_1.js -----
Function doClick1 ()
{
Alert ("okw.wufeng ");
}
// Script_2.js -----
Function doClick2 ()
{
Alert ("OK2 ");
}
2. In Solution Explorer, right-click to view the attributes of script_1.js and script_2.js, and set the "generate operation" attribute in advanced to "embedded resource ".
3. Add the following lines to the AssemblyInfo. cs file: (pay attention to 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, for example:
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
{
// Call the 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 );
}
///
/// Render control method RenderContents
///
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 );
}
}
}
You can try