Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

If you use the SPRibbon.TrimById() method on a specific button, it hides the button from the UI, which is okay. However in my case I think it would be nicer to simply disable the button and leave it in place.

I've seen a lot of articles using javascript with custom ribbon actions and triggering the script in their declarative markup for the custom button, but I'm trying to do this on a few OOTB buttons.

Is there any way to achieve this via C# using the SPRibbon class?

I want exactly what this guy on MSDN was asking for to no avail.

share|improve this question
1  
Still interested in finding a server side solution if it's available in the OM. –  RJ Cuthbertson Feb 13 at 14:36

2 Answers 2

up vote 4 down vote accepted

Can't you do a custom javascript to add the ms-cui-disabled class to the buttons you'd like to disable?

Edit: This just makes the button appear disabled but it will in fact be clickable. You might need to add the ms-cui-disabled class and a custom class so you can bind an onclick function to that custom class to prevent default and return false.

share|improve this answer
    
Is that all that needs to be changed to disable the link? If so, does that mean I could change the markup of a page in browser and enable buttons that are disabled? –  RJ Cuthbertson Feb 12 at 16:33
    
I tried it in firebug, it disables the button, but it is still clickable. You might need an additional on click function to prevent.default and return false for the buttons you want to disable. –  PirateEric Feb 12 at 16:37
    
Well, I just tried it in the developer tools, and adding that class does change the cursor etc. but it is still clickable. Also, removing that class from a disabled button isn't enough to re-enable it (there seems to be a few other changes like aria-disabled="true"), so that's good. So this does look like a viable path to achieve this. –  RJ Cuthbertson Feb 12 at 16:39

I don't have the exact command to hand but each ribbon button had a permissions mask property that you could set so only site collection admits have it enabled. This property is used as part of xml declaration of ribbon elements and may be accessible through c#. Failing that I think you would need to hide the ribbon button and the recreate in xml definition with the permissions mask only allowing site collection admins to see the button.

share|improve this answer
    
Yeah, that method would use the XML declarative button replacement approach, and I've seen replacing the value of the "perm" property on the items via javascript as well, but unfortunately I can't use the SP permissions for my use case. –  RJ Cuthbertson Feb 12 at 16:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.