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

RadListBox - ItemTemplate - ViewState

2 Answers 117 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Kathie
Top achievements
Rank 1
Kathie asked on 18 Oct 2011, 09:11 PM
Hello,

I am using a RadListBox in a custom Web User Control, which has an Item Template. I am dynamically adding items to the list box at runtime by passing the values to a property on the user control. In that property, I create the new item and set its properties as well as the properties on the controls within the item template. Upon callback, the actual items in the list box persist, but the values on the controls in the item template are lost (revert to defaults). The RadListBoxItem.Value is also lost. I also set the value of a custom attribute on the list item. That does survive the callback.

Any assistance would be appreciated.

Code:
'Load any pre-existing elements into the list box.
Public WriteOnly Property ConfigElements() As clsCommonObjects.ElementItem()
    Set(ByVal value() As clsCommonObjects.ElementItem)
        Dim intX As Int16
        Dim intY As Int16
 
        For intX = 0 To value.GetUpperBound(0)
            Dim objListItem As New RadListBoxItem
            lstAddedElements.Items.Add(objListItem)
            objListItem = lstAddedElements.Items(lstAddedElements.Items.Count - 1)
 
            objListItem.Text = ""
            objListItem.Value = value(intX).strType
 
            'Use an attribute to store the ID
            objListItem.Attributes.Add("UniqueID", value(intX).strID)
 
            For intY = 0 To objListItem.Controls.Count - 1
                Select Case objListItem.Controls(intY).ID
                    Case "lblElementType"
                        DirectCast(objListItem.Controls(intY), Label).Text = value(intX).strDisplayType
                    Case "lblElementName"
                        DirectCast(objListItem.Controls(intY), Label).Text = value(intX).strName
                    Case "imgElementType"
                        DirectCast(objListItem.Controls(intY), Image).ImageUrl = value(intX).strImageURL
                End Select
            Next
 
            objListItem = Nothing
        Next
 
    End Set
End Property

2 Answers, 1 is accepted

Sort by
0
Kathie
Top achievements
Rank 1
answered on 18 Oct 2011, 09:27 PM
A work around I found is to also place the property values for the controls in the Item Template into the Attributes collection since it is persisted properly upon callback. Then, in the Page_Load event use the attributes to reset the Item Template control properties. Not ideal, but it does work. I'd rather just have the Item Template controls persist the callback.
0
Genady Sergeev
Telerik team
answered on 21 Oct 2011, 07:33 AM
Hi Kathie,

This is a limitation within the ASP.NET runtime, the callbacks mechanism does not update the view state. More info can be found here.


Best wishes,
Genady Sergeev
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
Tags
ListBox
Asked by
Kathie
Top achievements
Rank 1
Answers by
Kathie
Top achievements
Rank 1
Genady Sergeev
Telerik team
Share this question
or