【问题标题】:ASP.NET, User Control and ViewState lost the correct data into try get into the user control eventASP.NET,用户控件和 ViewState 丢失了正确的数据,尝试进入用户控件事件
【发布时间】:2020-08-28 20:55:04
【问题描述】:

下午好,我有一个 ASP.NET 网页,我创建了一个用户控件,该控件具有一些我需要始终可检索的属性。 添加了 ViewState 以保留信息,但现在的缺点是,当在同一个 asp.net 页面上添加相同的控件时,并且从控件的函数中我想检索属性的值,这将检索最后输入的值在 ViewState 中。

非常感谢您。

<PersistenceMode(PersistenceMode.InnerProperty), TemplateInstance(TemplateInstance.Single)>
Public Property GuardadoTemporal() As Boolean
    Get
        If ViewState("GuardadoTemporal") Is Nothing Then
            Return false
        Else
            Return CBool(ViewState("GuardadoTemporal"))
        End If
    End Get
    Set(ByVal value As Boolean)
        ViewState("GuardadoTemporal") = value
    End Set
End Property

example for use

【问题讨论】:

    标签: asp.net properties failed-to-load-viewstate


    【解决方案1】:

    使用SaveControlStateLoadControlState https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.control.savecontrolstate?view=netframework-4.8 这会将其保存到每个控件的 controlstate 中,这样您就不会让用户控件破坏彼此的数据。 controlstate 也不能关闭

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      相关资源
      最近更新 更多