asp2.0 using public property

G

Guest

Can someone tell me why my integer variable _arrCnt is not holding its value.
I’m using ASP 2.0. I’m trying to use it in a public property routine to
count for my array. It keeps coming back with a 0 value instead of
incrementing.

Code sample from mainscreen.aspx

Partial Class mainscreen
Inherits System.Web.UI.Page
Dim clscmp As New clsCmpSetup
Dim arrStatement(10, 1)


Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim i As Integer
Dim bisTrue As Boolean = False
If Not bisTrue Then
ddlStatements.Items.Add(txtTitle.Text)
arrStatement(clscmp.ArrCnt, 0) = txtTitle.Text
arrStatement(clscmp.ArrCnt, 1) = txtStatements.Text
clscmp.ArrCnt = 1
End If

END SUB

Code sample from clsCmpSetup:

Imports Microsoft.VisualBasic

Public Class clsCmpSetup
Dim _arrCnt As Integer

Public Property ArrCnt() As Integer
Get
Return _arrCnt
End Get
Set(ByVal value As Integer)
If value < 0 Then
_arrCnt = 0
Else
_arrCnt = _arrCnt + 1
End If

End Set
End Property
End Class
 
G

Guest

Your clscmp varibale is being initialized every time the page is being
loaded, so _arrCnt is always 0. Depending on what it is you're trying to
achieve, look into storing either the clscmp object variable or the _arrCnt
variable in ViewState or Session state.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top