Umbraco: How to attach javascript file in umbraco by c#.

Umbraco provide a great way for attach javascript (.js) file in page mainly in user-control. For attaching js file all you need to do is call umbraco.library.RegisterJavaScriptFile()  method and pass name of js file and path of js file. And Mthod should be called in OnInit

Example  Working Code:

/// <summary>
/// On Init include js files
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
umbraco.library.RegisterJavaScriptFile("MyTest.js", "/scripts/TestApp/MyTest.js");

Hope this will help you 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s