Problem with template buttons in code behind

2 posts, 0 answers
  1. Ultravelocity
    Ultravelocity avatar
    13 posts
    Member since:
    Jun 2012

    Posted 10 Dec 2014 Link to this post

    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">
                    <telerik:RadToolBarButton Text="Sample" Value="Sample" />

    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";

  2. Plamen
    Plamen avatar
    3010 posts

    Posted 15 Dec 2014 Link to this post


    I have tested the described scenario and is worked correctly at my side. I am attaching the sample page that I used. Please review it and let me know if something else should be added or done in order to replicate the issue.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top