My asp.net/vb.net application has a code-behind file, PlanWizard.aspx.vb, that declares an ArrayList in the opening lines before any procedures as follow
Imports System.Data
Imports System.Data.SqlClient
Imports DAL
Partial Class WizardTest
Inherits System.Web.UI.Page
Private aryTaskWizarded As ArrayList
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.hidWizTaskID.Value = Request.QueryString("TaskID")
...
...
...
'Selected task will be the first item in array of tasks
aryTaskWizarded = New ArrayList()
aryTaskWizarded.Add(Me.hidWizTaskID.Value & "|" & Session("wizMainTaskName"))
'Populate aryTaskWizarded with all members of 'me.hidWizTaskID.value's branch where ListComplete is false
Sql = "execute uspBranchNotListComplete " & Me.hidWizTaskID.Value.ToString
Dim dr As SqlDataReader = SqlHelper.ExecuteReader(Sql)
While dr.Read
aryTaskWizarded.Add(dr("TaskID") & "|" & dr("TaskName"))
End While
dr.Close()
dr = Nothing
...
...
...
End If
End Sub
End Class
The Page_Load routine "sees" the aryTaskWizarded and runs as expected. The routine that runs when the Next button is clicked, however, crashes at a reference to the aryTaskWizarded variable. Here is that routine:
Protected Sub wizPP_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizPP.NextButtonClick
Dim sql As String = ""
Dim n As Integer = 0
Select Case wizPP.ActiveStepIndex
Case 1 'wizPP_OneDay
'Which radio button did user select?
Select Case CType(wizPP_OneDay.FindControl("rdoYesNoSkip"), RadioButtonList).SelectedValue.ToString
Case "Yes"
...
...
...
Case "No"
...
...
...
Case "Skip"
'Move this task to the end of the list
If (aryTaskWizarded.Count > 0) Then
'Copy current item on list
Dim TW As String = aryTaskWizarded(0)
'Delete from list
aryTaskWizarded.RemoveAt(0)
'If there's nothing left on the list, go to Finish
If aryTaskWizarded.Count = 0 Then
wizPP.ActiveStepIndex = 2
Else
'Add TW to the end of the list
aryTaskWizarded.Add(TW)
End If
End If
...
The program crashes when it encounters the line "If (aryTaskWizarded.Count > 0) then" and displays the message, "Object reference not set to an instance of an object."
The facts that this occurs within an asp.net Wizard control may be relevant. Can anyone tell me what I am doing wrong, and how I can make the aryTaskWizarded variable accessible to the wizPP_NextButtonClick event handler and other procedures within the module? Thanks for any help.