We have a RadToolbBar where we need to pro grammatically insert some buttons in the code behind. It works for the most part, except for buttons with an ItemTemplate. The toolbar is defined in the ASPX markup and has some buttons already. E.g.,
<telerik:RadToolBar ID="toolbar" runat="server">
<Items>
<telerik:RadToolBarButton Text="Sample" Value="Sample" />
</Items>
</telerik:RadToolBar>
In the Page_Init, we always insert additional buttons at the beginning of the toolbar (even on postback), e.g.
var btn= new RadToolBarDropDown();
btn.Text = "Test";
toolbar.Items.Insert(0, btn);
This appears to be working. However, we have buttons that use an ItemTemplate (using an ITemplate with an InstantiateIn method defined). These only work if we add to the end of the toolbar (toolbar.Items.Add(btn)), but not on Insert (toolbar.Items.Insert(0, btn)).
How do you insert a button with an ItemTemplate to the beginning of a statically defined RadToolbar?
The code used to insert the button:
var btn = new RadToolBarButton();
btn.Text = "Test";
btn.Value = "Test";
btn.ItemTemplate = new SampleTemplate();
toolbar.Items.Insert(0, btn);
The test template code:
public class SampleTemplate : ITemplate {
public void InstantiateIn(Control container) {
var label = new Label();
label.Text = "Test";
label.ID = "lblTest";
container.Controls.Add(label);
}
}
<telerik:RadToolBar ID="toolbar" runat="server">
<Items>
<telerik:RadToolBarButton Text="Sample" Value="Sample" />
</Items>
</telerik:RadToolBar>
In the Page_Init, we always insert additional buttons at the beginning of the toolbar (even on postback), e.g.
var btn= new RadToolBarDropDown();
btn.Text = "Test";
toolbar.Items.Insert(0, btn);
This appears to be working. However, we have buttons that use an ItemTemplate (using an ITemplate with an InstantiateIn method defined). These only work if we add to the end of the toolbar (toolbar.Items.Add(btn)), but not on Insert (toolbar.Items.Insert(0, btn)).
How do you insert a button with an ItemTemplate to the beginning of a statically defined RadToolbar?
The code used to insert the button:
var btn = new RadToolBarButton();
btn.Text = "Test";
btn.Value = "Test";
btn.ItemTemplate = new SampleTemplate();
toolbar.Items.Insert(0, btn);
The test template code:
public class SampleTemplate : ITemplate {
public void InstantiateIn(Control container) {
var label = new Label();
label.Text = "Test";
label.ID = "lblTest";
container.Controls.Add(label);
}
}