Compile JS files into dynamic link library (DLL) files

Source: Internet
Author: User

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 );
}

/// <Summary>
/// Render control method 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 );
}
}
}

You can try

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.