Compile the js file into a dll for page calling. jsdll

Source: Internet
Author: User

Compile the js file into a dll for page calling. jsdll

1. Add a project in solution: JSControl

2. Add a js file (JScript1.js) to this project)

Script content:

function showAlert(){alert('Today is a good dary');}

3. Change JScript1.js attributes and Build Action to Embedded Resource (Embedded Resource)

4. Add a line to the AssemblyInfo. cs file of the JSControl project: (Note: JSControl. JScript1.js, JSControl is the namespace, and JScript1.js is the file name)

[assembly: System.Web.UI.WebResource("JSControl.JScript1.js", "application/x-javascript")]

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

namespace JSControl{public class Class1 : System.Web.UI.WebControls.WebControl{protected override void OnPreRender(EventArgs e){if (this.Page != null){ClientScriptManager manager = this.Page.ClientScript;manager.RegisterClientScriptResource(typeof(Class1), "JSControl.JScript1.js");}base.OnPreRender(e);}}}

6. Add the reference of JSControl. dll to the js project.

7. Register JSControl. dll on the page where you want to call the script

<%@ Register Assembly="JSControl" Namespace="JSControl" TagPrefix="zhi" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

8. Call

<script type="text/javascript">$(function (){showAlert();});</script>

Compile a c ++ method into a dll file

Put the method in a DLL project and add _ declspec (dllexport) to export the function.

In B/S mode, how does one Call dll files through js?

There are many links in the following content, which are similar to this one !!!
 

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.