1. Add a JScript file to the Project
// Script_1.js -----
Function doclick1 ()
{
Alert ("okw.wufeng ");
}
// Script_2.js -----
Function doclick2 ()
{
Alert ("ok2 ");
}
2. In Solution Explorer, right-click to view the attributes of script_1.js and script_2.js, and set the "generate operation" attribute in advanced to "embedded resource ".
3. Add the following lines to the assemblyinfo. CS file: (pay attention to the domain name WF. clientscriptresourcelabel)
[Assembly: system. Web. UI. webresource ("WF. clientscriptresourcelabel. script_1.js", "application/X-JavaScript")]
[Assembly: system. Web. UI. webresource ("WF. clientscriptresourcelabel. script_2.js", "application/X-JavaScript")]
4. Add a class to the project, for example:
Using system;
Using system. drawing;
Using system. Web. UI;
Using system. Web;
Using system. Globalization;
Namespace WF. clientscriptresourcelabel
{
Public class clientscriptresourcelabel: system. Web. UI. webcontrols. webcontrol
{
// Call the script Resource
Protected override void onprerender (eventargs E)
{
If (this. Page! = NULL)
{
This. Page. clientscript. registerclientscriptresource (typeof (clientscriptresourcelabel), "WF. clientscriptresourcelabel. script_1.js ");
This. Page. clientscript. registerclientscriptresource (typeof (clientscriptresourcelabel), "WF. clientscriptresourcelabel. script_2.js ");
}
Base. onprerender (E );
}
/// <Summary>
/// Render control method rendercontents
/// </Summary>
Protected override void rendercontents (htmltextwriter output)
{
Output. addattribute ("ID", "1 ");
Output. addattribute ("type", "checkbox ");
Output. addattribute ("value", "Test 1 ");
Output. addattribute ("onclick", "javascript: doclick1 ();");
Output. renderbegintag (htmltextwritertag. Input );
Output. renderendtag ();
Output. addattribute ("ID", "2 ");
Output. addattribute ("type", "checkbox ");
Output. addattribute ("value", "Test 2 ");
Output. addattribute ("onclick", "javascript: doclick2 ();");
Output. renderbegintag (htmltextwritertag. Input );
Output. renderendtag ();
Base. rendercontents (output );
}
}
}