我有一个复合控件,它具有大量可用于设置控件样式的属性。我想对这些属性进行分组,但仍保留ViewState中的一些属性
控件的标记看起来像这样:
例如
<cc:Test id="test">
<Toolbar Items="add,delete" Enabled="true" />
<Grid Enabled="true" AllowSort="true" AllowFilter="true" />
</cc:Test>
我的代码看起来像这样
<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
无法从GridStyle类访问ViewState,那么如何在ViewState中维护AllowFilter属性的状态?
答案 0 :(得分:1)
在自定义控件中(或为自定义控件中使用的标准控件创建包装器),您需要覆盖SaveViewState和LoadViewState
这在MSDN和网络上有详细记载