RadListBox - ItemTemplate - ViewState

3 posts, 0 answers
  1. Kathie
    Kathie avatar
    5 posts
    Member since:
    May 2011

    Posted 18 Oct 2011 Link to this post

    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. Kathie
    Kathie avatar
    5 posts
    Member since:
    May 2011

    Posted 18 Oct 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 21 Oct 2011 Link to this post

    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
Back to Top