Adding custom button to ribbon - Button doesn't get displayed
-
07-12-2019 - |
سؤال
I'm trying to add a custom button to a SP2010 ribbon in the DisplayFormToolbar
for a list item. The list is external, although I don't think that matters but still...
This is my custom action definition:
<CustomAction Id="{0116B081-B13E-4A4B-8F8D-EF7AC1E43BFD}"
Location="DisplayFormToolbar"
RegistrationType="List"
RegistrationId="600"
Sequence="1"
ControlAssembly="myAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=...."
ControlClass="myNamespace.MyRibbonButton" />
myNamespace.MyRibbonButton
class extends System.Web.UI.WebControls.Button
and has some basic code inside OnInit
.
When I access the display form of an item in the external list, in debug I can see that OnInit
is executed, there is no exception in the logs... but the button does not show in the form!
I have specified my assembly with SafeControl
so that's not the cause.
Even if I add this to my custom action is still does not display:
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.Controls._children" />
</CommandUIDefinitions>
</CommandUIExtension>
What could I be missing?
المحلول
SharePoint 2010 ribbon doesn't have anything in common with 2007's DisplayFormToolBar
.
The custom action Location attribute should be set to "CommandUI.Ribbon" for adding something to ribbon.
Then, you should provide special XML for button. Since SP2010 ribbon is a client-side thing, no C# code is involved here.
You can find a simple example of adding a button to ribbon here:
P.S. Also, you can consider using SharePoint 2010 Fluent Ribbon API opensource project to work with ribbon in a simplified way. A quick how-to start can be found at project's documentation site. It is my project actually, and I cannot resist mentioning that it is a rather popular project and we use it in real-world projects at work intensively.