开发者

what variable i can use instead of shared?

开发者 https://www.devze.com 2022-12-25 03:15 出处:网络
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 t

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?

P开发者_JS百科ublic 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


Just remove Shared and everything should be fine.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号