Home All Groups Group Topic Archive Search About

Custom Collection Property Persistence

Author
29 Aug 2006 8:09 PM
swalkertdci
I have a composite control that I am working on that has a custom collection
property that is the type of another control. I believe I have all the
necessary atttributes set on the class and property (peristence,
parsechildren, etc...) but it still does not work properly.  I can access the
property in the designer just fine and add new control instances, but when I
close the property window none of the controls I just created are persisted
into the HTML. To recreate the problem I created a very simple server control
that demonstrates the behavior. The code is as follows:

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing

<ToolboxData("<{0}:ServerControlTest
runat=server></{0}:ServerControlTest>"), _
ParseChildren(True)> _
Public Class ServerControlTest
    Inherits CompositeControl

    Private moLabels As List(Of Label)

    <Browsable(True), _
    Category("Appearance"), _
    Description("The ribbon groups for this tab."), _
    PersistenceMode(PersistenceMode.InnerProperty), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public ReadOnly Property Labels() As List(Of Label)
        Get
            Return moLabels
        End Get
    End Property

#Region "Rendering"
    Protected Overrides Sub CreateChildControls()
        MyBase.CreateChildControls()

        Controls.Clear()
        CreateControlHierarchy()
        ClearChildViewState()
    End Sub

    Protected Sub CreateControlHierarchy()
        Me.Width = Unit.Pixel(200)
        Me.Height = Unit.Pixel(200)


        ' make sure we have controls to put in the content
        If Not moLabels Is Nothing Then
            For Each rb As Label In moLabels
                Me.Controls.Add(rb)
            Next
        End If
    End Sub


    Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
        Get
            Return HtmlTextWriterTag.Div
        End Get
    End Property
#End Region


End Class

If you try and use the "Labels" property in design mode you will see that
none of the labels added are properly persisted.

Can anyone please tell me why???