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