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 client script class
11 Clientscriptmanager CS = Page. clientscript;
12
13 // Register the client start script and display the client alarm message when loading the page
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 to handle the onclick event of the HTML buttonProgram
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 >