Display array values on page one at a time

stewarts

Newcomer
Joined
Apr 8, 2003
Messages
22
Hi,

I have an ASP .net page that contains a label and a NEXT button.

I want to display in the label, array values one at a time as the next button is pushed. This is the foundation that I will build further functionality on. This seems so simple, but I can’t figure out how to do it – I am new to asp .net. I’m trying to increment a counter to go through the array, but the counter keeps getting reset to zero. I hope someone can help me. THANKS! Here is my code:
Visual Basic:
Public Class AssignRecTypePerms
    Inherits System.Web.UI.Page
    Dim ctr As Integer

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            Dim SCArray(,) = CType(Session.Item("SessSCArray"), Array)
            lblSchoolCode.Text = SCArray(1, 0)
            ctr = 0
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        
        Dim SCArray(,) = CType(Session.Item("SessSCArray"), Array)
        ctr = ctr + 1
        lblSchoolCode.Text = SCArray(1, ctr)

    End Sub
End Class
 
Last edited by a moderator:
The counter is part of your page class, every time the page is refreshed the class is created, used and destroyed - this means all instance variables are also lost.

You would need to also store the counter variable in the Session state to make it persist between refreshes.
 
Back
Top