【问题标题】:How to store nested CompositeControl properties in ViewState如何在 ViewState 中存储嵌套的 CompositeControl 属性
【发布时间】:2009-03-17 23:45:09
【问题描述】:

我有一个复合控件,它具有大量可用于设置控件样式的属性。我想对这些属性进行分组,但仍保留 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 属性的状态?

【问题讨论】:

    标签: asp.net viewstate composite-controls


    【解决方案1】:

    在您的自定义控件中(或为自定义控件中使用的标准控件制作包装器)您需要覆盖 SaveViewState 和 LoadViewState

    这在 MSDN 和一般网络上都有很好的记录

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      相关资源
      最近更新 更多