473,320 Members | 2,161 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,320 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 1817
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.