Skip to main content

Register client side scripts in code behind

Quick way to register client side scripts.
 
 
Let us take the css files first:

CssLink cssLink = new CssLink();
cssLink.DefaultUrl = "/_layouts/appname/cssfiletoregister.css";
this.Page.Header.Controls.Add(cssLink);
 
 
string scriptPath = "/_layouts/appname/jstoregister.js";
if(!this.Page.ClientScript.IsClientScriptBlockRegistered(scriptPath))
    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), scriptPath,
    "

Comments