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

Controls disappeared when postback

1 Answer 86 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
camilla
Top achievements
Rank 1
camilla asked on 03 Feb 2010, 10:19 AM
I am trying to dynamically create some RadPanelItems according to the user input no. e.g. When user input 3, I will dynamically create 3 RadPanelItems. And in each RadPanelItems will have some textboxes and button for user to use. The controls in each RadPanelItem are the same. But when the use click on the button inside the RadPanelItem. All the runtime created controls disappeared. Is there anything work arround to solve that?

Hear is my code

    Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If txtNoOfInd.Text.Trim IsNot String.Empty Then

            CreatePanels(txtNoOfFrm.Text)
        end if
   End Sub

Sub CreatePanels(ByVal NoOfFrm As Integer)

            For i As Integer = 1 To NoOfInd

                Dim NoOfPersons As Integer = txtNoOfInd.Text

                Dim table1 As HtmlTable
                Dim Row As HtmlTableRow
                Dim Cell As HtmlTableCell
                Dim txtName As TextBox
                Dim lblName As Label
                Dim btnNext As Button

                txtName = New TextBox
                txtName.ID = "txtName" & i.ToString

                lblName = New Label
                lblName.ID = "lblName" & i.ToString
                lblName.AssociatedControlID = "txtName" & i.ToString
                lblName.Text = "Name:"

                btnNext = New Button
                btnNext.ID = "btnNext" & i.ToString
                btnNext.Text = "Next"

                table1 = New HtmlTable
                Row = New HtmlTableRow
                Cell = New HtmlTableCell

                Cell.Controls.Add(lblName)
                Cell.Controls.Add(txtName)
                Cell.Controls.Add(btnNext)
                Row.Cells.Add(Cell)
                table1.Rows.Add(Row)

                Dim newParentItem As RadPanelItem = New RadPanelItem()
                Dim newChildItem As RadPanelItem = New RadPanelItem()

                newParentItem.Items.Add(newChildItem)
                newChildItem.Controls.Add(table1)
                newParentItem.Text = i.ToString
                If i = 1 Then
                    newParentItem.Expanded = True
                End If

                RadPanelBar1.Items.Add(newParentItem)
            Next
    End Sub



1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 04 Feb 2010, 12:33 PM
Hi Camilla,

Dynamically added controls to RadPanelBar items are not preserved and should be added on every postback.

All the best,
Yana
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
PanelBar
Asked by
camilla
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or