如何在 ViewState 中存储嵌套的 CompositeControl 属性

发布于 2024-07-15 22:07:38 字数 1126 浏览 6 评论 0原文

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

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青芜 2024-07-22 22:07:38

在您的自定义控件中(或为自定义控件中使用的标准控件制作包装器),您需要覆盖 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文