Friday, July 8, 2011

How to add JavaScript in Custom SharePoint Web Parts

While creating a web part I had to use some JavaScript. There are definitely other ways of doing this, I am just sharing the way I did it.

clip_image002

JavaScript file would also reside in the same folder structure in 12 hive, however while adding it in the code, used the Client script Manager

////-- Adding JavaScript file ----------

ClientScriptManager cs = Page.ClientScript;

if (!cs.IsClientScriptIncludeRegistered("tab_javascript"))

{

cs.RegisterClientScriptInclude(this.GetType(), "tab_javascript",

"/_layouts/A/Scripts/Script.js");

}

Please post a comment if you have other ways of doing this same thing… I’ll be happy to hear.

HaPpY CoDiNg... (Aurum)

No comments:

Post a Comment