Did you know that you can remove buttons from SharePoint ribbon in code?

I am not sure if this behaviour is normal. I guess i have to investigate it another time. If you develop a listform using Visual Studio and based on an application page like i wrote in some other posts about it, you might notice, that in the edit and new form the save and cancel button does not work. They just do not firing the event.

The solution to this is really easy. In the schema file or by using code you change the listform url and also make the setting “UseLegacyForm” to true.

<form Type="NewForm" Url="NewForm.aspx" SetupPath="features\$SharePoint.Feature.DeploymentPath$\List1\NewSP.aspx" UseLegacyForm="TRUE" WebPartZoneID="Main"></form>

Doing so makes the save and cancel button working again, but now you have another stupid behaviour. Look at the screen: It is a generic / custom list as template, but it also shows buttons for edit series, claim release, distribution approval. What the hell is going on here?


I googled, tested but nothing worked for me. I thought that the connection is lost between ribbon and listform, but it seems not to be.

The only thing which helped me, was trimming the ribbon buttons one by one. Using the code below in the onPreRender method of my listform page.

protected override void OnPreRender(EventArgs e)
SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
ribbon.TrimById("Ribbon.ListForm.Edit.Actions.EditSeries", "false");
ribbon.TrimById("Ribbon.ListForm.Edit.Actions.ClaimReleaseTask", "false");
ribbon.TrimById("Ribbon.ListForm.Edit.Actions.DistributionListsApproval", "false");
if(this.FormToolBar.ControlMode == SPControlMode.New)
ribbon.TrimById("Ribbon.ListForm.Edit.Actions.DeleteItem", "false");


After deploying it with the code lines above it looks like this:


That’s what i can’t explain at the moment, but if you got an idea, let me know.

Well my other post are here:

Part 1: Setting up a solution with a list definition, a list instance and deploy it.

Part 2: Creating a custom list form and connect it with the list definition.

Part 3: Necessary settings for custom listform in Visual Studio

Part 4: Override Save Button in listform


The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

Karsten Schneider
About Karsten Schneider 302 Articles
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

Be the first to comment

Leave a Reply

Your email address will not be published.