我使用以下变量,当我使用同一Web表单的多个实例时会产生问题。你能告诉我除了共享以外我可以用什么变量来实现这个目的吗?
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
答案 0 :(得分:1)
只需删除Shared
,一切都应该没问题。
答案 1 :(得分:0)
这是很多工作,但它创建了表单级存储
对于每个共享变量,将其转换为WebForm上的属性。然后将值存储在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
这样,值与页面保持一致。
请注意我是动态编码的,而不是VS,所以你可能需要调整它。