views:

591

answers:

1

Hello !

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 dissapeared 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 doeing something wrong when dynamically adding items ?

Thank You !

+1  A: 

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.

Genady Sergeev
Hi. Thanks for reply ! got one more little question :)what about child RadPanelItem?it's created dynamically, and item itself is not lost after postback.
vbobruisk