The Ajax method is used to write JavaScript scripts to pages in the post code (. CS file,
Although response. Write ("<SCRIPT> script content </SCRIPT>"); you can also write script code to the page,
However, the content output by the script is mostly at the top of the page. You can use the following method to write the script content anywhere you want.
Clientscriptmanager cs = This. clientscript;
CS. registerarraydeclaration ("hello", "1, 2, 3 ");
CS. registerclientscriptblock (this. GetType (), "helloworld", "function helloworld () {alert (1) ;}", true );
CS. registerclientscriptinclude ("helloworld", "helloworld. js ");
CS. registerexpandoattribute (this. button1.clientid, "hello", "world ");
CS. registerhiddenfield ("hello", "world ");
CS. registeronsubmitstatement (this. GetType (), "helloworld", "Return window. Confirm ('Do you really want to submit the form? ')");
CS. registerstartupscript (this. GetType (), "helloworld", "<SCRIPT> alert ('the page has loaded! ') </SCRIPT> ");
The above is the usage of script registration. The following is a note:
// RegisterarraydeclarationEffect is to define an array
// --------- The generated script is: var Hello =New array (1, 2, 3 );
// RegisterclientscriptblocK results in a function, followed by the form tag in the source code
// --------- Generated Script: function helloworld () {alert (1 );}
// RegisterclientscriptinclUde references external JS files
// --------- The generated script is: <SCRIPT src = "helloworld. js" type = "text/JavaScript"> </SCRIPT>
// Registerhiddenfield generates a hidden control named "Hello World ".
// --------- The generated script is: <input type = "hidden" name = "hello" id = "hello" value = "world"/>
// RegisteronsubmitstatemenT
// --------- The generated script is: function webform_onsubmit () {return window. Confirm ('Do you really want to submit the form? '); Return true ;}
// Registerstartupscript generates a function, and the position follows the ending form tag.
// --------- The generated script is: <SCRIPT> alert ('the page has loaded! ') </SCRIPT>