This is a migrated thread and some comments may be shown as answers.

Problem with template buttons in code behind

1 Answer 35 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Ultravelocity
Top achievements
Rank 1
Ultravelocity asked on 10 Dec 2014, 07:34 PM
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);
        }
    }











1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 15 Dec 2014, 12:14 PM
Hello,

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.

Regards,
Plamen
Telerik
 

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.

 
Tags
ToolBar
Asked by
Ultravelocity
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or