How to compile a. js file into a DLL for page calling

Source: Internet
Author: User
1. Add a new project (Class Library: jscontrol) to the solution)
2. Add the JS script (jscript1.js) to the new project)
 
FunctionTestalert (){

Alert("Hello! ");
}

3. Right-click jscript1.js and set build action to embedded resource.

4. Add a line to the assemblyinfo. CS file of the jscontrol project: (Note that jscontrol. jscript1.js is the namespace of the project where JS is located)CopySave

 
// Define metadata attributes of embedded resources in a component

[Assembly: system. Web. UI. webresource ("Jscontrol. jscript1.js","Application/X-JavaScript")]

5. Add a class for registering client scripts in the jscontrol project: referencescript. CSCopySave

NamespaceJscontrol
{
Public ClassReferencescript: system. Web. UI. webcontrols. webcontrol
{
Protected Override VoidOnprerender (eventargs E)
{
If(This. Page! =Null)
{
Clientscriptmanager manager =This. Page. clientscript;
Manager. registerclientscriptresource (Typeof(Referencescript ),"Jscontrol. jscript1.js");
}
Base. Onprerender (E );
}
}
}

6. Reference The jscontrol project in the website project and generate jscontrol. dll after compilation.

7. Register jscontrol. dll on the page to call the scriptCopySave

<% @RegisterAssembly ="Jscontrol" Namespace ="Jscontrol" Tagprefix ="Zhi" %>

8. reference scriptsCopySave

 
<Zhi: referencescript Id ="RS1"Runat ="Server"/>

<ASP: button Id ="Btnreadxml" Runat ="Server" TEXT ="Readxml" Onclick ="Btnreadxml_click"
Onclientclick ="Testalert ();" />

9.

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.