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>