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

UserControls in dynamically created PanelBarItems lost on Postack

2 Answers 91 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Tamayi
Top achievements
Rank 1
Tamayi asked on 21 Jun 2012, 03:57 AM
What I'm trying to do is perhaps pretty simple:

  • Allow the user to select several configuration options from a drop down list.
  • Each configuration option has a user control associated with it and when the user selects the option, the User Control with the configuration details must display allowing the user to capture some info.
  • The user can select any number of configuration options, and this in itself might result in a very loooong form as more configuration choices are selected.

I'm hoping RadPanelBar can help prevent the form growing too long by allowing collapseing behaviour in the configuration section for me.

I keep track of the choices which the user has selected (in a hidden form variable) , and with each choice, the specific user control which must be loaded. The problem I'm currently facing is that the RadPanelBar only displays the very last item on PostBack, losing the controls from all previous choices. I reload the controls in the Page_Init event.
Private Property MyUsedControls As Dictionary(Of Long, MyUsedControl)
 
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
 
    MyUsedControls = MyUsedControl.DeserializeReportList(Request.Form(HiddenField1.UniqueID))
 
    'Recreate the controls. At this stage, the RadPanelBar1.Items collection is empty
    For i As Integer = 0 To MyUsedControls.Count - 1
 
        Dim ctrl As MyUsedControl = MyUsedControls(i)
        AddConfigurationControl(ctrl.ControlPath)
 
    Next
 
End Sub
 
Private Sub AddConfigurationControl(ByVal cPath As String)
 
    Dim p As New RadPanelItem("Control No. " & RadPanelBar1.Items.Count)
    Dim uc As Control = LoadControl(cPath)
 
    Dim content As New RadPanelItem()
    content.Controls.Add(uc)
 
    p.Items.Add(content)
 
    RadPanelBar1.Items.Add(p)
 
End Sub
 
Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged
 
    'Here we add the control to our "memory" of what controls we have so far used
    'This is persisted into a hidden form variable without any problems
    MyUsedControls.Add(
        MyUsedControls.Count,
        New MyUsedControl With {
            .ID = RadPanelBar1.Items.Count,
            .ControlPath = RadComboBox1.SelectedValue
        }
    )
 
    AddConfigurationControl(RadComboBox1.SelectedValue)
 
    RadComboBox1.ClearSelection()
 
End Sub

You can download a copy of the source code here: Sample Code: RadControlsWebApp1 (link expires 19 August 2012)

2 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 25 Jun 2012, 08:36 AM
Hello Tamayi,

Can you specify the exact version of Telerik controls and .NET that you are using? Have you tried with the latest version from the Q2 2012 release for .NET 4.0?

Kind regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tamayi
Top achievements
Rank 1
answered on 25 Jun 2012, 08:55 AM
I am using the latest version of Telerik 2012.2.607.35 on .NET 3.5
Tags
PanelBar
Asked by
Tamayi
Top achievements
Rank 1
Answers by
Peter
Telerik team
Tamayi
Top achievements
Rank 1
Share this question
or