Compile the js file into a dynamic link library (dll) file _ Javascript tutorial

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.