Several methods of using ASP. NET background code to call JavaScript scripts at the front end

Source: Internet
Author: User
  

many users call client functions on the server, that is, they call the script functions defined in JavaScript scripts in ASP. After research, we found some stubborn methods.

1. use response. write method write script

for example, after you click the button, you must first operate the database, and then the operation is complete, you can write
response. write (" ");

This method has a defect that it cannot call the custom functions in the script file. It can only call internal functions. The specific call of custom functions can only be in response. write the function definition in write, such as response. write (" ");

2. use the clientscript class to dynamically add scripts

usage: Add Code . Make sure that myfun has been defined in the script file.

clientscript. registerstartupscript (clientscript. getType (), "myscript", "");

compared to response. write is more convenient. You can directly call the custom functions in the script file.

3. ordinary add control attributes

for common buttons: button1.attributes. add ("onclick", "myfun ();");

the value can only be added in onload or during onload initialization. In addition, the script function is executed first, and the execution sequence cannot be changed.

note: In all the above methods, the background Code cannot convert the code on the current page, such as redirect, put the page-turning code in the script

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.