How to register js in asp.net background, asp.net background js
1. Use the Response. Write Method
The Code is as follows:
Response. Write ("<script type = 'text/javascript '> alert (" hello "); </script> ");
This method is flawed because it cannot call the User-Defined Functions in the script file. It can only call internal functions. The specific user-defined functions can only be defined in Response. Write.
For example:
Response. Write ("<script type = 'text/javascript '> function myfun () {...} </script> ");
2. Use ClientScript class
This method is more convenient than Response. Write. You can directly call the UDF in the script file.
Add code where you want to call a javascript script function. Make sure that MyFun has been defined in the script file.
The Code is as follows:
ClientScript. RegisterStartupScript (ClientScript. GetType (), "myscript", "<script> MyFun (); </script> ")