By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,743 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,743 IT Pros & Developers. It's quick & easy.

VB.NET ASP.NET application forgets value of variable. Is this a bug?

P: n/a
How can I retain the value in memory in the ASP.NET Web application?

NOTE: This example works correctly (increments the value) when the
you create a VB.NET Windows Application, but does not work (the value
keeps getting reset to zero) when you create an ASP.NET Web
Application. Is this a bug in .NET, or am I doing something wrong?

In the ASP.NET version, I tried replacing "Dim objPerson As New
PersonDetails" with
A. "Public objPerson as New PersonDetails" (got same results)
B. "Friend objPerson as New PersonDetails" (got same results)
C. "Static objPerson As New PersonDetails" (got syntax error)
HOW TO RECREATE THE ISSUE:
Create a new VB.NET Windows application.

PROJECT | Add Class
Name = PersonDetails.vb
Public Class PersonDetails
Private m_iNumber As Integer

Public Sub AddOne()
M_iNumber = m_iNumber + 1
End Sub

Public Property CurrentValue() As Integer
Get
CurrentValue = m_iNumber
End Get
Set(ByVal Value As Integer)
m_iNumber = Value
End Set
End Property

Add this to the code-behind of Form1.vb, before any Subs or functions:
Dim objPerson As New PersonDetails()
Add a button to the form. The code behind =
objPerson.AddOne
Response.Write (objPerson.Value) 'use this for VB.NET Asp.NET
application
MsgBox (objPerson.Value) 'use this for VB.NET windows application
Each time you click on the button, it should increment the value, and
it does for the VB.NET Windows application, BUT IT DOES NOT with the
VB.NET ASP.NET application (it stays at 1). How do I get around this?


Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
It's not a bug. You may want to make the property shared for instance. I
think the object is getting reset on the post back. If the property is
shared, you won't have this happen. You can also use a Session variable and
increment it each time...

HTH,

Bill
"re**************@nospam.com" <se*@website.com> wrote in message
news:2t********************************@4ax.com...
How can I retain the value in memory in the ASP.NET Web application?

NOTE: This example works correctly (increments the value) when the
you create a VB.NET Windows Application, but does not work (the value
keeps getting reset to zero) when you create an ASP.NET Web
Application. Is this a bug in .NET, or am I doing something wrong?

In the ASP.NET version, I tried replacing "Dim objPerson As New
PersonDetails" with
A. "Public objPerson as New PersonDetails" (got same results)
B. "Friend objPerson as New PersonDetails" (got same results)
C. "Static objPerson As New PersonDetails" (got syntax error)
HOW TO RECREATE THE ISSUE:
Create a new VB.NET Windows application.

PROJECT | Add Class
Name = PersonDetails.vb
Public Class PersonDetails
Private m_iNumber As Integer

Public Sub AddOne()
M_iNumber = m_iNumber + 1
End Sub

Public Property CurrentValue() As Integer
Get
CurrentValue = m_iNumber
End Get
Set(ByVal Value As Integer)
m_iNumber = Value
End Set
End Property

Add this to the code-behind of Form1.vb, before any Subs or functions:
Dim objPerson As New PersonDetails()
Add a button to the form. The code behind =
objPerson.AddOne
Response.Write (objPerson.Value) 'use this for VB.NET Asp.NET
application
MsgBox (objPerson.Value) 'use this for VB.NET windows application
Each time you click on the button, it should increment the value, and
it does for the VB.NET Windows application, BUT IT DOES NOT with the
VB.NET ASP.NET application (it stays at 1). How do I get around this?

Nov 22 '05 #2

P: n/a
It's not a bug. You may want to make the property shared for instance. I
think the object is getting reset on the post back. If the property is
shared, you won't have this happen. You can also use a Session variable and
increment it each time...

HTH,

Bill
"re**************@nospam.com" <se*@website.com> wrote in message
news:2t********************************@4ax.com...
How can I retain the value in memory in the ASP.NET Web application?

NOTE: This example works correctly (increments the value) when the
you create a VB.NET Windows Application, but does not work (the value
keeps getting reset to zero) when you create an ASP.NET Web
Application. Is this a bug in .NET, or am I doing something wrong?

In the ASP.NET version, I tried replacing "Dim objPerson As New
PersonDetails" with
A. "Public objPerson as New PersonDetails" (got same results)
B. "Friend objPerson as New PersonDetails" (got same results)
C. "Static objPerson As New PersonDetails" (got syntax error)
HOW TO RECREATE THE ISSUE:
Create a new VB.NET Windows application.

PROJECT | Add Class
Name = PersonDetails.vb
Public Class PersonDetails
Private m_iNumber As Integer

Public Sub AddOne()
M_iNumber = m_iNumber + 1
End Sub

Public Property CurrentValue() As Integer
Get
CurrentValue = m_iNumber
End Get
Set(ByVal Value As Integer)
m_iNumber = Value
End Set
End Property

Add this to the code-behind of Form1.vb, before any Subs or functions:
Dim objPerson As New PersonDetails()
Add a button to the form. The code behind =
objPerson.AddOne
Response.Write (objPerson.Value) 'use this for VB.NET Asp.NET
application
MsgBox (objPerson.Value) 'use this for VB.NET windows application
Each time you click on the button, it should increment the value, and
it does for the VB.NET Windows application, BUT IT DOES NOT with the
VB.NET ASP.NET application (it stays at 1). How do I get around this?

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.