G
Guest
If have an asp.net page (code behind written in VB.NET) which needs to store
information from a postback in an arraylist and retain this list across
multiple postbacks.
The variable is declared at the class level as:
Public files As New ArrayList
And I am accessing it in two event procedures. (fileList is an ap:listbox
control and fileUploadBox is an HtmlInputFile control with runat="server"):
Private Sub addFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles addFile.Click
If IsPostBack And fileUploadBox.Value <> "" Then
files.Add(fileUploadBox)
fileList.Items.Add(fileUploadBox.PostedFile.FileName)
End If
End Sub
Private Sub removeFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles removeFile.Click
If fileList.Items.Count <> 0 And fileList.SelectedIndex <> -1 Then
files.RemoveAt(fileList.SelectedIndex)
fileList.Items.Remove(fileList.SelectedItem.Text)
End If
End Sub
The addFile_Click procedure works fine and the files arraylist is updated;
however, when the removeFile_Click procedure runs the files arraylist is
always empty.
I thought that the contents of any global variables was automatically
maintained across postbacks but this doesn't seems to be working. How can I
do this?
Many thanks for any help.
Alan
information from a postback in an arraylist and retain this list across
multiple postbacks.
The variable is declared at the class level as:
Public files As New ArrayList
And I am accessing it in two event procedures. (fileList is an ap:listbox
control and fileUploadBox is an HtmlInputFile control with runat="server"):
Private Sub addFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles addFile.Click
If IsPostBack And fileUploadBox.Value <> "" Then
files.Add(fileUploadBox)
fileList.Items.Add(fileUploadBox.PostedFile.FileName)
End If
End Sub
Private Sub removeFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles removeFile.Click
If fileList.Items.Count <> 0 And fileList.SelectedIndex <> -1 Then
files.RemoveAt(fileList.SelectedIndex)
fileList.Items.Remove(fileList.SelectedItem.Text)
End If
End Sub
The addFile_Click procedure works fine and the files arraylist is updated;
however, when the removeFile_Click procedure runs the files arraylist is
always empty.
I thought that the contents of any global variables was automatically
maintained across postbacks but this doesn't seems to be working. How can I
do this?
Many thanks for any help.
Alan