Export (0) Print
Expand All

EcmaScript and the Server Ribbon

SharePoint 2010

Last modified: February 07, 2011

Applies to: SharePoint Foundation 2010

There are multiple ways to add ECMAScript (JavaScript, JScript) to a page in Microsoft SharePoint Foundation. This topic lists the most common techniques for adding JavaScript to a page to interact with the Server ribbon.

You can put custom JavaScript on the page using one of the following methods:

  • Target a delegate control on the page, such as AdditionalPageHead.

  • Add a Web Part on the page.

  • Use ScriptLink for the Location attribute on a custom action.

You can add a control to the AdditionalPageHead delegate to insert JavaScript in the page. Use this method when you are targeting a specific list for customization. When you are working with a specific document library or list, the control can determine the current list and output the JavaScript as necessary. Outputting the script in this manner is done for performance reasons. You can use the ClientScriptManagerRegisterClientScriptBlock() method of the System.Web.UI.Page object to output the script.

You can add Web Parts on the page and register script by using the ClientScriptManagerRegisterClientScriptBlock() method of the System.Web.UI.Page object or by inserting it directly into the page. You should use this method of adding JavaScript when the Server ribbon button is related to the Web Part that emits the JavaScript.

Using ScriptLink as the Location attribute on a custom action adds script on the page at the Microsoft.SharePoint.SPSite level. All pages in the site will have the script on the page. Use this type of customization when JavaScript is used on most pages within a site.

The type of customization you use depends on the scope of the scenario. For an example of a site collection–level replacement of a button on the ribbon, see Walkthrough: Replacing a Button on the Server Ribbon for a Site Collection.

Show:
© 2014 Microsoft