简体   繁体   中英

what variable i can use instead of shared?

I have the following variable which creates problem when i use multiples instance of the same web form. Could you please let me know how i could what variables other than shared i can use to achieve this purpose?

Public strRoleType As String = String.Empty
Protected Shared isAreaSelected As Integer = 0
Protected Shared isStoreSelected As Integer = 0
Protected Shared isHeadOfficeSelected As Integer = 0
Protected Shared isRegionSelected As Integer = 0

只需删除“ Shared ,一切都会正常。

This is a lot of work but it creates form level storage

For each of your shared variables convert it to a property on the WebForm. Then store the values in the ViewState

'default to 0 if blank, else convert to int
Public Property IsAreaSelected() As Integer
    Get
        Return If(ViewState("IsAreaSelected") Is Nothing, 0, Cint(ViewState("IsAreaSelected")))
    End Get
    Set(ByVal value As Integer)
        ViewState("IsAreaSelected") = value
    End Set
End Property

This way the values stay with the page.

Please note I coded this up on the fly and not in VS so you may have to tweak it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM