0

I have created a custom ribbon button for my list. For some pages I wanted to hide the ribbon button and for some pages I wanted to disabled. I found how to make disabled, I wrote following code to make disabled.

 <CommandUIHandler Command="{A9424973-D302-4D7D-98B9-7489B6682780}" CommandAction="~site/SitePages/Test.aspx" 
                          EnabledScript="javascript:
    function isEnable(){
      if(location.href.indexOf('MyPage/DispForm.aspx') > 0){
        return true;
      }
      return false;
    }
    isEnable();"/>

My problem is how to hide ribbon button using CommandUIHandler. Anybody has an idea?

  • 1
    you are hiding it with commanduihandler, what do you expect? – Gwny Apr 22 '16 at 8:41
  • 1
    This command makes it disable but didn't hide the button in ribbon. @Gwny – Hardik Apr 22 '16 at 8:45
  • I wanted to hide my custom action anyhow for specific page/ or visible it for specific page – Sivakumar Piratheeban Apr 22 '16 at 8:51
  • 1
    so your code does not work? – Gwny Apr 22 '16 at 9:06
  • Above code is work only for disabling, I need a solution to hide it. – Sivakumar Piratheeban Apr 22 '16 at 9:09
1

You can try this: add another Custom Action with a Location set to where you want to hide it - for example attach it to list with a specific content type, or to a list based on a custom template (there are many different locations, just Google around):

<CustomAction
      Id="RemoveRibbonButton"
      Location="CommandUI.Ribbon"
      RegistrationType="List"
      Sequence="10001"
      RegistrationId="10115">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="SET_THIS_TO_LOCATION_OF_YOUR_RIBBON_BUTTON" />
      </CommandUIDefinitions>
    </CommandUIExtension>
  </CustomAction>

For example if you wanted to remove the original New Item button, you would set the Location of CommandUIDefinition to this: Location="Ribbon.ListItem.New.NewListItem"

Exclude the CommandUIHandler node from the XML completely and set Sequence number higher than on your other CustomAction. What will happen in this case - your original button will be added to the Ribbon and then your second CustomAction will overwrite it. Since the CommandUIHandler will be missing - the button will be hidden.

1

Have you try to use : HideCustomAction ??

With this, you can hide specific custom (the custom and OOTB CustomAction).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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