Question

i've got a question about Telerik RadPanelBar control.

For example we've got a RadPanelBar control on form :

        <telerik:RadPanelBar ID="testPanelBar" runat="server">
        </telerik:RadPanelBar>

and a button which adds a new item to this RadPanelBar at runtime:

        RadPanelItem newParentItem = new RadPanelItem();
        RadPanelItem newChildItem = new RadPanelItem();
        newChildItem.Controls.Add(new RadTextBox());
        newChildItem.Text = "wazzap";
        newParentItem.Items.Add(newChildItem);
        languagesPanelBar.Items.Add(newParentItem);

when i click button, new RadPanelItem is added with all child controls(in this case it's RadTextBox in child item)

when button is clicked second time, second RadPanelItem is added with all controls, but this time RadTexBox control disappeared from first RadPanelItem.

And same when button is clicked for third time, new item added with all controls, but RadTextBox will dissapear from 1st and 2nd items.

Am I doing something wrong when dynamically adding items ?

Thank You !

Was it helpful?

Solution

This happens because dynamically created controls added to other dynamically created controls are lost after a postback. You need to recreate them on every page load. As far as I know there is no workaround for this issue. You can easily reproduce it with the Page class too, on page_load try Controls.Add(new TextBox()); Then after a postback, the same code will not generate new (second) textbox, but will recreate the later.

All PanelBar items (even dynamically created ones) are serialized on the client and after a postback are recreated on the server. And this is why they are not lost. However,the same thing does not apply to the child controls of the RadPanelItem object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top