Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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:

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

Edited by PlausiblyDamp
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...