Response. Write, RegisterClientScriptBlock, and RegisterStartupScript summary,
Response. Write, RegisterClientScriptBlock, and RegisterStartupScript summary Page. ClientScript. RegisterStartupScript usage summary original link: http://blog.csdn.net/qiujialongjjj/article/details/6680252 Register the startup script with the Page Object using the type, key, script text, and Boolean value indicating whether to add the script tag. The type of the startup script to be registered. Key of the startup script to be registered. The STARTUP script text to register. AddScriptTags indicates whether to add a Boolean value marked by the script. Note: The STARTUP script is uniquely identified by its key and type. Scripts with the same key and type are considered as repeated scripts. Only scripts of the given type and key pair can be registered on this page. Trying to register a registered script will not create repeated scripts. // The ASP. NET background Page jumps to Page. ClientScript. RegisterStartupScript (Page. GetType (), "", "<script> if (confirm ('saved successfully! Continue adding? ') {Location. href = 'productonadd. aspx '} else {location. href = 'productonlist. aspx '} </script> "); // The confirmation box ClientScript is displayed in the background. registerStartupScript (GetType (), "message", "<script> alert ('enter it correctly! '); </Script> "); // ASP. NET background Page Jump. clientScript. registerStartupScript (Page. getType (), "", "<script> alert ('data added successfully! '); {Location. href = 'productonlist. aspx '} </script> "); or Page. clientScript. registerStartupScript (typeof (string), "", "<script> window. location. href = 'adminmain. aspx '; </script> "); // the text box ScriptManager is displayed in the background. registerStartupScript (Page, typeof (string), "popUp", "window. open ('rptview. aspx ', 'print preview', 'toolbar = no, location = no, scrollbars = yes, top = 200px, left = 200px, width = 904px, height = paipx ')", true); ClientScript. registerStartupScript instructions: http://blog.csdn.net/wcp88888888/article/details/5870386 ClientScript. registerStartupScript is used to register a script to the front-end page. There are two overload Methods: ClientScript. registerStartupScript (Type type, string key, string script); ClientScript. registerStartupScript (Type type, string key, string script, bool flag); the former requires "<script> </script> ". the latter can be directly written as ClientScript. registerStartupScript (Type. getType (), "", jsScript name, true); in this way, you can automatically add <script> </script> when registering at the front-end. Another important item is the key, if the key settings are the same, the first one will overwrite the following jsScri Pt code, but no effect, so you need to set the key differently when using it. For example, string JavaScript = @ "<script language = javascript> alert ('test 1'); </script>"; ClientScript. registerStartupScript (this. getType (), "javaScript", javaScript); string javaScript2 = @ "<script language = javascript> alert ('test 2'); </script>"; ClientScript. registerStartupScript (this. getType (), "javaScript2", javaScript2); Response. the difference between Write, RegisterClientScriptBlock, and RegisterStartupScript is as follows: http://blog.csdn.net/gxiangzi/article/details/7252737 This method will write the js Code at the top of the page (before
- RegisterStartupScript.
This method embeds the JS Code in the bottom of the page and in front of the form (</form>). It is applicable to the JS Code to run after the page control is loaded:
- RegisterClientScriptBlock
This method will embed the JS Code at the top of the page and at the beginning of the form (<form> ), applicable to the JS code to be executed before the control is loaded. If your script has a statement that interacts with the Page Object (doucument object), we recommend that you use RegisterStartupScript, if you want to execute the client script as early as possible, you can use RegisterClientScriptBlock and Response. write.