. Net background code calls front-end JS in two ways

Source: Internet
Author: User

1. This method can only call simple JS Code. User-defined functions cannot be called.
Copy codeThe Code is as follows:
String jss = "<script language = 'javascript 'Type = 'text/javascript '> alert ('hello') </script> ";
Response. Write (jss );

2. General methods. Mya () is a UDF defined in the front-end code.

(1)
Copy codeThe Code is as follows:
String sl = "<script language = 'javascript 'Type = 'text/javascript '> mya ('hes') </script> ";
Page. ClientScript. RegisterStartupScript (ClientScript. GetType (), "mya", sl );
 
(2)
Copy codeThe Code is as follows:
String sl = "<script language = 'javascript 'Type = 'text/javascript '> mya ('hes') </script> ";
Page. RegisterStartupScript ("mya", sl); // The RegisterStartupScript method of the Page is outdated. Use the RegisterStartupScript method of ClientScript.


Page. ClientScript attributes

Obtain the ClientScriptManager object used to manage scripts, register scripts, and add scripts to pages. // Call this property to return a ClientScriptManager object.

Note:
Use the ClientScript attribute to obtain a ClientScriptManager object that can be used to manage scripts, register scripts, and add scripts to webpages. For more information, see ClientScriptManager class.

The ClientScriptManager class is a new class in ASP. NET 2.0. It replaces the Page class method that has been denied for script management.


ClientScriptManager class

Define a method for managing client scripts in a Web application.

ClientScriptManager. RegisterStartupScript method // dynamically Add a script to the client

Register the startup script with the Page object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.