I am facing trouble removing the "Edit Item" ribbon button from calendar DispForm.aspx.

I have created a visual studio 2010 user control where i used the method TrimById("Ribbon.ListForm.Display.Manage.EditItem"); and deployed the solution.

Next I went into calendar's master page and used the control created in the Register tag. If it worked the "Edit Item" in DispForm.aspx should not appear, but it does. Please tell me if I did miss any steps.

1 Answer 1


SharePoint provides ability to remove ribbon elements using custom actions. This method was tested and I think it is more preferrable and much more flexible, than inserting your custom controls into your masterpage. At least, because custom actions approach is available for sandboxed solutions.

In your case, you probably should use following code to define such custom action:

        <CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.EditItem" />

106 here is the ID of Events list template. If you have your custom list template or standard template other than Events, you should use it instead of 106 value.

If you want to attach your ribbon customizations to a single list, rather than to a list template, you can use SPList.UserCustomActions collection. In your feature receiver you should place following code:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    // considering your feature is web-scoped
    var web = properties.Feature.Parent as SPWeb;

    // fetch SPList object, it must have been created before using this code
    var list = web.GetListFromUrl("path/to/list/AllItems.aspx");

    // create new customAction
    var customAction = list.UserCustomActions.Add();

    // this is for cleanup purposes in FeatureDeactivating
    customAction.Name = properties.Feature.DefinitionId.ToString("N") + "_ribbon";

    // setting custom action location, and the CommandUIExtension element
    customAction.Location = "CommandUI.Ribbon.DisplayForm";
    customAction.CommandUIExtension = @"
          <CommandUIDefinition Location=""Ribbon.ListForm.Display.Manage.EditItem"" />

    // saving the changes to database

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    // cleanup code

    SPWeb web = properties.Feature.Parent as SPWeb;
    var list = web.GetListFromUrl("path/to/list/AllItems.aspx");

    bool collectionChanged = false;
    for (int i = list.UserCustomActions.Count - 1; i >= 0; i--)
        var customAction = list.UserCustomActions.ElementAt(i);

        if (customAction.Name.StartsWith(properties.Feature.DefinitionId.ToString("N")))
            collectionChanged = true;

    if (collectionChanged)
  • Hello omlin, the custom action you mentioned must be used in Elements.xml file if I am not mistaken. But I had a client requirement where I need to remove some other ribbon buttons as well. So the best thing to do was to use Visual studio and utilize the code in usercontrol. Please do suggest some solutions so that I can make my code work. May 23, 2011 at 11:53
  • Yes, it's done with Elements.xml. But you can define as many CommandUIDefinition elements, as you wish, so you can remove several buttons at one time. I think using elements.xml here is much better, because it will work for sandboxed solutions too, unlike the usercontrol solution. And also this method was tested many many times and it works perfectly... May 23, 2011 at 12:01
  • Hello omlin, thanks for the quick response. Could you please tell me how to do this in visual studio and how to actually remove buttons using the Elements.xml file. Please provide some references on how to achieve it. Thanks May 23, 2011 at 12:04
  • Hello, I need the information about the Id and RegistrationId. I have the customized list so obviously the RegistrationId won't be 106. So how do I actually find/set the RegistrationId for my custom list. And is this Id="RemoveEditItemButtonFromCalendar" customizable or is the default Id to be used when removing the buttons??? And also by using Elements.xml the "Edit Button" will be removed for all the calendar's present in the site. How to restrict it to just one calendar only. Thanks May 23, 2011 at 12:24
  • Id can be whatever you want. Registration Id must point to your list template id. This will assign your customization to all the lists with specified template (including even non-existant). For assigning customizations to concrete existing list, you can use SPList.UserCustomActions. If you give me a few hours, I'll update my answer with detailed explanation how all this can be done (now I have no chance to do this because of lack of time at work). May 23, 2011 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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