| I always wanted to do some custom controls and perform some UI verification. So I needed to use the embedded JS file. I found some materials and some examples. I found that I could not. First, I set the JS file as an embedded resource, However, [Assembly: webresource ("syj0.dir0. the description of syj0 in js1.js "," application/X-JavaScript ", javasmsubstitution = true)] is different. some are namespaces and some are project names. none of them are correct. Cause Analysis: these materials are basically the same as the created Project and namespace, so there may be no problems. However, the projects I created are different project names. For example, the project name of the control library I created is webctrls, and the default namespace of the Project is modified to syj0.CodeThe namespace in uses syj... (a bit confusing ). So some examples found on the Internet cannot be run, either not responding, or an error is prompted... Final Solution: [Assembly: webresource ("syj0.dir0. js1.js", "application/X-JavaScript", required msubstitution = true)] syj0 should be the default namespace name in the Project Properties window. The following is the path of the JS file, as shown in syj0.dir0. js1.js. The js1.js file under the dir0 directory under the namespace syj0 is used by default. Of course, this. Page. clientscript. registerclientscriptresource (this. GetType (), "syj0.dir0. js1.js"); Do not write this sentence incorrectly. Please note that the case sensitivity is not tested. Pay attention to the Case sensitivity. The following is an example of a complete control library project: [Class1.cs] Using system; Using system. Web. UI. webcontrols; Using system. Web. UI; [Assembly: webresource ("syj0.jscript1. js", "application/X-JavaScript", required msubstitution = true)] [Assembly: webresource ("syj0.dir0. js1.js", "application/X-JavaScript", required msubstitution = true)] Namespace syj { Public class stextbox: webcontrol, inamingcontainer { Protected textbox = new Textbox (); Protected override void onprerender (eventargs E) { This. Page. clientscript. registerclientscriptresource (this. GetType (), "syj0.jscript1. js "); This. Page. clientscript. registerclientscriptresource (this. GetType (), "syj0.dir0. js1.js "); Base. onprerender (E ); } Protected override void rendercontents (system. Web. UI. htmltextwriter writer) { This. textbox. Attributes. Add ("ID", this. ID ); This. textbox. Attributes. Add ("onclick", "MSG (this); Showtime ();"); This. textbox. rendercontrol (writer ); } } } // Jscript1.js Function MSG (OBJ) { Alert ("hello from web control s JS File ID [" + obj. ID + "]"); } // Dir0.js1. js Function Showtime () { Alert (new date ()); } Usage: Use vs2008 to create a solution, create a default web project as webapplication, and then create a library project. Replace the class1.cs content of the Library Project with the above content, and then directly create a JScript under the project. create a folder dir0 and create a js1.js file in dir0. The content is described above. Compile and go to the ASPX page of the web project. When the toolbox is opened, the custom control stextbox is displayed. drag one to the page, press Ctrl + F5, and click the input box to see the result. |