0

Good afternoon, I have an ASP.NET web page and I created a user control that has some properties that I need to always be retrievable. ViewState was added to keep information, but the drawback now is that when adding the same control on the same asp.net page and from within a function of the control I want to retrieve the value of the property, this will retrieve the last value entered in the ViewState .

Beforehand thank you very much.

<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

M0u53GT
  • 3
  • 1

1 Answers1

0

Use SaveControlState and LoadControlState https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.control.savecontrolstate?view=netframework-4.8 This will save it into the controlstate for each control so you don't get user controls clobbering each others data. controlstate can't be turned off either

Salik Rafiq
  • 174
  • 1
  • 7