如何在 ViewState 中存储嵌套的 CompositeControl 属性
我有一个复合控件,它具有大量可用于设置控件样式的属性。 我想对这些属性进行分组,但仍保留 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
ViewState 无法从 GridStyle 类访问,那么我将如何维护 ViewState 中的AllowFilter 属性的状态?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的自定义控件中(或为自定义控件中使用的标准控件制作包装器),您需要覆盖 SaveViewState 和 LoadViewState
这在 MSDN 和 Web 上都有详细记录
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