Alexis Mercier
Guest
|
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. |
|
Andrei Smolin
Add-in Express team
Posts: 18827
Joined: 2006-05-11
|
Hi Alexis,
Please check the code sample included in the manual, the section is "Creating Ribbon Controls Dynamically".
Andrei Smolin
Add-in Express Team Leader |
|
Alexis Mercier
Guest
|
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. |
|
Dmitry Kostochko
Add-in Express team
Posts: 2875
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
adxspRibbonMenuSection2.Controls.Clear();
// 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
adxspRibbonMenuSection2.Controls.Add(btn1);
ADXSPRibbonButton btn2 = new ADXSPRibbonButton(this.components);
btn2.Id = "my_id_2";
btn2.JSVarName = "btn2";
btn2.Caption = "Caption 2";
btn2.Ribbons = adxspRibbonMenuSection2.Ribbons;
adxspRibbonMenuSection2.Controls.Add(btn2);
ADXSPRibbonButton btn3 = new ADXSPRibbonButton(this.components);
btn3.Id = "my_id_3";
btn3.JSVarName = "btn3";
btn3.Caption = "Caption 3";
btn3.Ribbons = adxspRibbonMenuSection2.Ribbons;
adxspRibbonMenuSection2.Controls.Add(btn3);
}
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. |
|