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

ItemTemplate not working when buttons are dynamically added server-side

1 Answer 86 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Louis asked on 28 May 2014, 02:23 AM
We have been using RadToolbar for a very long time, but until recently we had never used the ItemTemplate functionality.

While we can display the templates correctly, we are encountering a significant issue when the page is posted back: the templates are not rendered after postback completes.

After a significant amount of troubleshooting, we have tracked the issue down to dynamically added buttons. We have static templates for most toolbars (defined in a skin), but there are several cases where we need to dynamically add buttons to every toolbar rather than adjusting all of the skins.

As soon as we insert a new toolbar item after the templated items, the templated items will no longer render after a postback (we have not tried inserting before because that is not something that we need to do.

We have tried removing and re-adding the dynamic toolbar items and simply ignoring them if they already exist on a postback, but in both cases, the templated items are not rendered.

I have a sample project that demonstrates the issue, but am not allowed to attach it to this thread.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 May 2014, 07:31 AM
Hi Louis,

Please have a look into the sample code snippet which works fine at my end. 

ASPX:
<telerik:RadToolBar ID="RadToolBar1" runat="server">
    <Items>
        <telerik:RadToolBarButton Text="Item1">
        </telerik:RadToolBarButton>
        <telerik:RadToolBarButton Text="Item2">
        </telerik:RadToolBarButton>
    </Items>
</telerik:RadToolBar>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    Label label = new Label();
    label.ID = "Label1";
    label.Text = "Label1";
    RadToolBarButton toolbarButton1 = RadToolBar1.FindItemByText("Item1") as RadToolBarButton;
    toolbarButton1.Controls.Add(label);
    RadButton button = new RadButton();
    button.ID = "RadButton1";
    button.Text = "RadButton";
    RadToolBarButton toolbarButton2 = RadToolBar1.FindItemByText("Item2") as RadToolBarButton;
    toolbarButton2.Controls.Add(button);
}

Let me know if you have any concern.
Thanks,
Princy.
Tags
ToolBar
Asked by
Louis
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or