The best way to add JavaScript to the end of ASP. NET is to add JavaScript to the end of ASP. NET.

Source: Internet
Author: User

How do I add JavaScript scripts or libraries to the end of the Asp.net page before the end mark of the page? Several methods are summarized for reference.

1 Use registerclientscriptincludeBetterReferences to JavaScript Library (jsfile. JS:
 
If (! Page. clientscript. isclientscriptincluderegistered ("jsfileinclude") page. clientscript. registerclientscriptinclude ("jsfileinclude", "jsfile. js ");

Add a javascript library reference at the beginning of the viewstate data document.

2 To add some JavascriptCodeInsert to page You can use the registerstartupscript method:
String jscodeblock = "Var mystr = 'where'; alert (mystr);"; if (! Page. clientscript. isstartupscriptregistered ("myjscode") page. clientscript. registerstartupscript (typeof (string), "myjscode", jscodeblock, true );
The javascript code is added to the end of the document.

When the last parameter is set to true, the. NET Framework is automatically added to the scriptLabelStart and end (or merge the Code with other generated JavaScript code based on the same script tag ).

However, you can also use the registerstartupscript method,At the end of the documentLoad the reference to the Javascript library, write the complete JS file, and set the last parameter to false:
String jsfile ="<ScriptSRC= \ "Jsfile. js \"Type= \ "Text/JavaScript \"> </Script>"; If (! Page. clientscript. isstartupscriptregistered ("myjsfileref") page. clientscript. registerstartupscript (typeof (string), "myjsfileref", jsfile, false );

 

URL: the best way to add JavaScript to the end of ASP. NET

123

Related Article

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.