In ASP. net2.0, The clientscriptmanager class uniquely identifies a script by the string and type keys. Scripts with the same key and type are considered as repeated scripts. Therefore, we can use the script type to avoid obfuscation of similar scripts that may be used on pages from different user controls. <HTML>
<Head>
<Title> clientscriptmanager example </title>
</Head>
<Body>
<Form ID = "form1"
Runat = "server">
<Input type = "text" id = "message"> <input type = "button" value = "clickme" onclick = "doclick ()">
</Form>
</Body>
</Html>
1 <% @ page Language = "C #" %>
2 <SCRIPT runat = "server">
3 Public void page_load (Object sender, eventargs E)
4 {
5 // define the client script type and name
6 string csname1 = "popupscript ";
7 string csname2 = "buttonclickscript ";
8 Type cstype = This. GetType ();
9
10 // instantiate a new class of client script
11 clientscriptmanager cs = page. clientscript;
12
13 // register the client start script. The client alarm message is displayed when the page is loaded.
14 if (! CS. isstartupscriptregistered (cstype, csname1 ))
15 {
16 string cstext1 = "alert ('Hello World ');";
17 CS. registerstartupscript (cstype, csname1, cstext1, true );
18}
19
20 // register the client to execute the script and define the client handler for The onclick event of the HTML button
21 if (! CS. isclientscriptblockregistered (cstype, csname2 ))
22 {
23 stringbuilder cstext2 = new stringbuilder ();
24 cstext2.append ("<SCRIPT type = text/JavaScript> function doclick (){");
25 cstext2.append ("form1.message. value = 'text from client script. '} </");
26 cstext2.append ("script> ");
27 CS. registerclientscriptblock (cstype, csname2, cstext2.tostring (), false );
28}
29}
30 </SCRIPT>
-
Reference: http://www.knowsky.com/340038.html