Using RegisterClientScriptInclude in ASP.NET

The final method for registering Javascript in an ASP.NET page is the RegisterClientScriptInclude method. Most developers place JavaScript inside a .js file, which is considered best practice because it makes it simple to make global JavaScript changes to the app and .js pages are cached. You can register the script files on your ASP.NET pages using the ClientScriptInclude method as shown below:

string myJavaScript = "myJsCode.js";
Page.ClientScript.RegisterClientScriptInclude("myKey", myJavaScript);

This creates the following tag in your ASP.NET page:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>