Tuesday 18 October 2011

Disabling Ribbon button {not hiding it} Conditionally SharePoint 2010


There are various Options to hide Ribbon buttons from the entire site or site colletcion but we needed a solution to Disable a ribbon button for few lists only. The button should work as supoosed to be on rest of the lists.

The easiest way we could found out was to use Enable script of the Ribbon button and add register the Javascript clinet Object model script using Additionalpageheader delegate control on each page of the site.

Here are the Steps that we did -

1. Created a new Ribbon Button

2. In <customaction> tag of ribbon button in your elements.xml file, In CommandAction specify the function name that will run when the ribbon button will be clicked.

3. In EnabledScript="javascript:ecmascriptFunctionName();" that will determine the list and enable or disable the Ribbon button.

4. Add the ScriptLink custom Action to refer the javascript file for e.g.
<CustomAction
Id="RibbonButton.Script"
Location="ScriptLink"
ScriptSrc ="/_layouts/RibbonScripts/CheckIfNeedToEnable.js"/>
</Elements>

5. Next add a new Delegate User control in your solution "addionalPageHeader". This will only be used to register the CheckIfNeedToEnable.js on all pages of the site since the delegate control is deployed in the MasterPage header. See and example Using Delegate Controls to insert Javascript in SharePoint pages

6. Next, add the .js file in your solution under _layouts usign SharePoint Mapped Folders.

7. Lastly, add the ecmascript code to check the current list name and hide the ribbon button if its not the desired list.

Ads by Google

No comments:

Post a Comment