Thursday, April 14, 2011


In this post we will discuss how to call external script (js) files in web part in SharePoint 2010?

Also you can check out:

- How to create a custom field type in SharePoint 2010 using visual studio 2010?

- How to get page title and URL in SharePoint 2010 using server object model?

- Remove hyperlink from title column in SharePoint 2010 list view

This stuff is done by my Tech Lead K, Kathiravan from HP. He was working on a web part (not visual web part) and need to call an external .js file. Here is the code sample:

protected override void OnPreRender(EventArgs e)
{
Page.ClientScript.RegisterStartupScript(GetType(), "MyScript",
"", false);
base.OnPreRender(e);
}

Put the js file as per the location given in the code. And one important thing to remember is that You should not write any script tag inside the js file, else it will give an error. Because script inside script is not allowed.


0 Comments:

Post a Comment