views:

500

answers:

1

I have a composite control that has a large number of properties that can be used to style the control. I want to group these properties yet still maintain some of the properties in the ViewState The markup for the control would look like this:
e.g.

<cc:Test id="test">
    <Toolbar Items="add,delete" Enabled="true" />
    <Grid Enabled="true" AllowSort="true" AllowFilter="true" />
</cc:Test>

My code looks something like this

<ParseChildren(true)> <PersistChildren(true)> _
Public Class Test Inherits CompositeControl

    Private _grid As New GridStyle();
    <PersistenceMode(PersistenceMode.InnerProperty)> _
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public ReadOnly Property Grid As GridStyle
        Get
            Return _grid;
        End Get
    End Property
End Class

Public Class GridStyle
    private _allowFilter As Boolean = False;
    Public Property AllowFilter As Boolean
        Get
            Return _allowFilter
        End Get
        Set(value As Boolean)
            _allowFilter = value
        End Set
    End Property
End Class


ViewState is not accessible from the GridStyle class so how would I maintain the state of the AllowFilter property in the ViewState?

+1  A: 

In your custom control (or make wrappers for standard controls used within a custom control) you need to override SaveViewState and LoadViewState

This is well documented on MSDN and the web in general