Method One:
Page.registerclientscriptblock method
Name space: System.Web.UI
This method is now obsolete. Use the Clientscriptmanager.registerclientscriptblock method instead
Example: Page.registerstartupscript ("GGG", "");
Method Two:
<asp:literal id= "Ltscript" runat= "Server" ></asp:Literal>
Then use the literal class when the background code is used
Private void Button1_Click (object Sender,system.eventargs e) { "<script type=/" text/javascript/"> The JS function you want to perform;</script>";}
Method Three:
is one of the most flexible, clientscript.registerstartupscript
Example: StringBuilder sb = new StringBuilder ();
Sb. Append ("<script language= ' JavaScript >");
Sb. Append ("Button2_onclick ('" + Serverpath + "')");
Sb. Append ("</script>");
Clientscript.registerstartupscript (this. GetType (), "Loadpicscript", sb. ToString ());
Method Four:
Writing scripts using the Response.Write method
For example, after you click the button, the database is finished, the display is finished, you can write in the last place to call
Response.Write ("<script type= ' Text/javascript ' >alert ();</script>");
One drawback of this approach is that you cannot invoke a custom function in a script file, only call an intrinsic function, and call a custom function to write function definitions only in Response.Write, such as Response.Write ("<script type= ' text/ JavaScript ' >function myfun () {...} </script> ");
Method Five:
Dynamically adding scripts with the ClientScript class
Use the following: Add code where you want to invoke a JavaScript script function, and be sure that Myfun has already been defined in the script file.
Clientscript.registerstartupscript (Clientscript.gettype (), "MyScript", "<script>myfun ();</script>");
This method is more convenient than Response.Write, you can directly invoke the custom function in the script file.
View Original
C # Background execution JavaScript