G
gce
What happens :
When I first press the button, I get an listbox1 with a,b,c (correct:
because of the
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")
When I check the checkbox, the eventhandler triggers and when I press the
button, the addtoa(4,"d") works fine, because I have a listbox with a,b,c,d
But now the strange thing. When I press the button again, the d is lost
again. This is just a testcode, but in my program I have the same problem
with adding something to an array inside a handler using the session var.
Please help me !
Public Class frmArrayTest1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim a
ReDim Preserve a(4, 4)
AddHandler CheckBox1.CheckedChanged, AddressOf
CheckBox1_CheckedChanged
Session("test") = a
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")
End Sub
Private Sub addtoa(ByVal intIndex, ByVal strString)
Dim a
'ListBox1.Items.Add(strString)
a = Session("test")
a(intIndex, 2) = strString
Session("test") = a
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CheckBox1.CheckedChanged
addtoa(4, "d")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x
Dim i
x = Session("test")
ListBox1.Items.Clear()
For i = 1 To UBound(x)
ListBox1.Items.Add(Str(i) & "-" & x(i, 2))
Next i
End Sub
End Class
When I first press the button, I get an listbox1 with a,b,c (correct:
because of the
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")
When I check the checkbox, the eventhandler triggers and when I press the
button, the addtoa(4,"d") works fine, because I have a listbox with a,b,c,d
But now the strange thing. When I press the button again, the d is lost
again. This is just a testcode, but in my program I have the same problem
with adding something to an array inside a handler using the session var.
Please help me !
Public Class frmArrayTest1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim a
ReDim Preserve a(4, 4)
AddHandler CheckBox1.CheckedChanged, AddressOf
CheckBox1_CheckedChanged
Session("test") = a
addtoa(1, "a")
addtoa(2, "b")
addtoa(3, "c")
End Sub
Private Sub addtoa(ByVal intIndex, ByVal strString)
Dim a
'ListBox1.Items.Add(strString)
a = Session("test")
a(intIndex, 2) = strString
Session("test") = a
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CheckBox1.CheckedChanged
addtoa(4, "d")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x
Dim i
x = Session("test")
ListBox1.Items.Clear()
For i = 1 To UBound(x)
ListBox1.Items.Add(Str(i) & "-" & x(i, 2))
Next i
End Sub
End Class