Dynamic menu items

Add-in Express™ Support Service
That's what is more important than anything else

Dynamic menu items
A sample demonstrating how to add menu items. 
This forum has moved to a new location. From now on, please post all your questions about Ribbon Designer for SharePoint on this forum.
Alexis Mercier

Posts: 2
Joined: 2012-01-23
Hi Folks,

I see that "Support for dynamic menu items" was added in the release version. Do you have a code sample that could help me with adding menu items? Thank you in advance.
Posted 23 Jan, 2012 06:19:01 Top
Andrei Smolin

Add-in Express team

Posts: 15595
Joined: 2006-05-11
Hi Alexis,

Please check the code sample included in the manual, the section is "Creating Ribbon Controls Dynamically".

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Jan, 2012 06:26:06 Top
Alexis Mercier

Posts: 2
Joined: 2012-01-23
Hi Andrei,

Thanks but your manual gives a client-side JavaScript code. Can I do the same in C#, on a server side? We have a list of 3-6 items that are managed by admin only, all the users should have the same list in a split button.
Posted 24 Jan, 2012 03:26:36 Top
Dmitry Kostochko

Add-in Express team

Posts: 2752
Joined: 2004-04-05
Hi Alexis,

Of course, you can add your controls at run-time with server-side code. You need to handle the OnLoad event, create your 3-6 controls/buttons and add them to the ADXSPRibbonMenuSection.Controls collection. Please see the code below:

private void EmptyListRibbon2_OnLoad(object sender, System.Web.UI.Page page)
    // clear the Controls collection

    // create a new button
    ADXSPRibbonButton btn1 = new ADXSPRibbonButton(this.components);
    // set properties
    btn1.Id = "my_id_1";
    btn1.JSVarName = "btn1";
    btn1.Caption = "Caption 1";
    btn1.Ribbons = adxspRibbonMenuSection2.Ribbons;
    // add the button to the Controls collection

    ADXSPRibbonButton btn2 = new ADXSPRibbonButton(this.components);
    btn2.Id = "my_id_2";
    btn2.JSVarName = "btn2";
    btn2.Caption = "Caption 2";
    btn2.Ribbons = adxspRibbonMenuSection2.Ribbons;

    ADXSPRibbonButton btn3 = new ADXSPRibbonButton(this.components);
    btn3.Id = "my_id_3";
    btn3.JSVarName = "btn3";
    btn3.Caption = "Caption 3";
    btn3.Ribbons = adxspRibbonMenuSection2.Ribbons;

Please make sure the PopulateDynamically property of your split button is set to false. If it is true, you need to handle the OnMenuCreate client-side event and add your controls in this event handler as described in our documentation that Andrei referred to.
Posted 24 Jan, 2012 05:54:03 Top