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.

[sourcecode language=”csharp”]


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.

[sourcecode language=”csharp”]

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.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. 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.