473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
2 1824
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Art | last post by:
Can I update Application("SomeVariableName") on server A in response to user's action on server B? There is no problem in updating the same variable on server B, of course, but we would like both...
1
by: refer_to_website | last post by:
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...
2
by: evangeline | last post by:
We have ASP application running on IIS 5.1 and Windows 2000 server. The ASP application has few Application variables setup in global.asa. Something like this: Application.Lock()...
8
by: rene | last post by:
Hi all, please look into this small piece of code and tell me why my values weren't stored. Ive searched for hours on an explanation, but found none. Ive got an class with (in this example) 2...
8
by: Mike Turco | last post by:
This is a strange one. I have an app that needs to know who is using the program but there's no need for security. When the program opens a form comes up with a listbox. The user double-clicks...
4
by: mvivar | last post by:
Hi everybody: This will be not easy to explain as my mother language is not english, so my apologies in advance if it sounds confusing. We have a database access 97 wich controls time of...
2
by: Jaikanth Sithambaranathan via .NET 247 | last post by:
The problem is in the result page in which i can scroll throughthe contents of the result set 100 at a time. I call the resultpage from a filter page where i accept filter on results to bedisplayed....
2
by: Oberon | last post by:
Why does this not work as it should? I expect index.aspx to show:. Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\ChatSimple\db\chatusers.mdb Instead, I get: ...
3
by: Daniel Friend | last post by:
I have an application and use custom user controls as plugins. Is there any way to communicate back and forth from control to app. NOTE: The control is not refrenced in the app, it will act as a...
2
by: parkchan | last post by:
Hi all, I've got an weird problem with Application variables in Global.asax.vb. I have three Application variables set up in Session_OnStart event and I'm displaying the values of those...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.