To compile the JS file into a DLL for the page call method _ Practical skills

Source: Internet
Author: User

1. Add a project to the solution: Jscontrol

2. Add a JS file to this project (Jscript1.js)

The contents of the script:

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

3. Change the properties of the Jscript1.js, build action for embedded Resource (embedded resources)

4. Add a row to the AssemblyInfo.cs file for the Jscontrol project: (Note that Jscontrol.jscript1.js,jscontrol is a namespace, jscript1.js is a filename)

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

5. Add a class that registers client script 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 a JSControl.dll reference to a project that calls JS

7. Page registration to invoke script JSControl.dll

<%@ 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>

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.