473,763 Members | 5,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about data persistence in Public variables

I have a public variable that is declared in a public module. This Variable
is stored into a Session variable and used to pass data from page to page.
I am seeing on my local development box that once the variable is created
and loaded with data and stored into the session variable that on the next
aspx page, before the first line of the page load is executed, the public
variables data persists. I have not done an assignment from the session
variable into the public variable to load the memory address back. Is this
just a fluke or is this the way things are suppose to work? How does my
public variable know what memory address to use? Can anyone point me to a
white paper that describes how session variables and public variables are
handled in memory? Any input would be greatly appreciated. Thanks.

Public Module Globals
Public gSettings As GlobalSettings
End Module
Jan 20 '06 #1
7 2081
KJ
The members of a module are implicitly marked Shared. What this means
is that these members have the same lifetime as Shared members. A
Shared variable has only a single lifetime, which lasts for the entire
time your application is running.

Jan 20 '06 #2
KJ,

Thank you for the reply. I think your not following what I am stating. I am
talking about ASP.NET code. It is my understanding ASP.NET is not in itself
stateful thus when you go from one asp page to another page your variables
need to be re-addressed to memory spaces. Session and/or Cache is used to
hold information on the IIS server from page to page. You need to assign the
Session/Cache data back into a declared variable in order to access it.
That is my understanding but it is not what I am seeing.

Steps to duplicate what I am seeing.
1) create aspx page that loads data into a public variable declared in a
public module and.saves that variable into the session with the
session("X") = Variable also place a link button on page to goto page 2.

2) Create ASPX page 2 and in debug mode set break points before you start
processing this page.

3) run page 1 click on link on page and when you hit debug link on page two
check the value of the public variable. I am seeing the data stored in it
on page one without having to do an assignment statement (i.e. public
variable = session("X")). This does not seem right to me and I am wanting
to know is this by design or is this "Feature" that should not be counted on
to work the same way every time.

Thanks again.

"KJ" <n_**********@m ail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
The members of a module are implicitly marked Shared. What this means
is that these members have the same lifetime as Shared members. A
Shared variable has only a single lifetime, which lasts for the entire
time your application is running.

Jan 20 '06 #3
KJ
Hi Steve,

Thanks for the more detailed explanation. I will try to better state
the point I made earlier using your analogy.

The public variable you mention is implicity marked Shared. This means
that its scope is application-wide. So, once the value is initially set
by page #1, the value persists because it is a module-level member
(Shared), not an instance-level member. The runtime ensure that this is
so (try it with other module-level members).

Module-level members (Shared members) are visible across the
application domain, and this is the reason page #2 can see the value
set by page #1 (they are in the same appdomain).

You do not even need to use the session object to accomplish the
cross-page persistence of that member's value, because it is persisted
in the application domain of the asp.net application (of each page is a
part).

Jan 20 '06 #4
KJ,

I am only seeing the public variable data persist from page to page if it is
stored in the session variable. If I remove the Session("X") = Public
Variable on the first asp page then on the load for the second page the
Public variable has a value of Nothing.
"KJ" <n_**********@m ail.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Hi Steve,

Thanks for the more detailed explanation. I will try to better state
the point I made earlier using your analogy.

The public variable you mention is implicity marked Shared. This means
that its scope is application-wide. So, once the value is initially set
by page #1, the value persists because it is a module-level member
(Shared), not an instance-level member. The runtime ensure that this is
so (try it with other module-level members).

Module-level members (Shared members) are visible across the
application domain, and this is the reason page #2 can see the value
set by page #1 (they are in the same appdomain).

You do not even need to use the session object to accomplish the
cross-page persistence of that member's value, because it is persisted
in the application domain of the asp.net application (of each page is a
part).

Jan 20 '06 #5
KJ
That does sound odd. I will try to replicate it at home at get back to
you. Meanwhile, if anyone else is lurking on this thread and has any
ideas...

Jan 21 '06 #6
KJ
Steve,

I tried the code below, but was unable to duplicate the issue. Let me
know if the code below was a valid attempt at replicating the issue.

*** code follows ***
' Module code

Module TestModule1
Public GlobalSettingsI nstance As New GlobalSettings
End Module

Public Class GlobalSettings
Public Int1 As Int32 = Int32.MinValue
End Class

'aspx #1

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
GlobalSettingsI nstance.Int1 = 567
'Session("GSI") = GlobalSettingsI nstance 'tried with this commented
and uncommented
End Sub

Private Sub lbtnGoToPage2_C lick(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles lbtnGoToPage2.C lick
Response.Redire ct("TestPage2.a spx", False)
End Sub

'aspx #2
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Response.Write( "Hello World") 'breakpoint here reveals .Int1 member =
567, regardless of session call in aspx #1
End Sub

Jan 22 '06 #7
KJ,

Sounds like you duplicated my issue in that the data is persisted topage two
Page_load without setting GlobalSettingsI nstance. Having data in the
GlobalSettingsI nstance before an assignment statement is counter intuitive
to me. Is this data persistence by design? If so why have I not seen any
references to it in any ASP.NET documentation as a way of persisting data
between pages? Here is a microsoft document that covers data persistence in
asp.net and nowhere in it is Public variables in a public module mentioned
as a method of persisting data between pages.
http://msdn.microsoft.com/msdnmag/is...e/default.aspx

Thanks,

Steve Mauldin


"KJ" <n_**********@m ail.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Steve,

I tried the code below, but was unable to duplicate the issue. Let me
know if the code below was a valid attempt at replicating the issue.

*** code follows ***
' Module code

Module TestModule1
Public GlobalSettingsI nstance As New GlobalSettings
End Module

Public Class GlobalSettings
Public Int1 As Int32 = Int32.MinValue
End Class

'aspx #1

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
GlobalSettingsI nstance.Int1 = 567
'Session("GSI") = GlobalSettingsI nstance 'tried with this commented
and uncommented
End Sub

Private Sub lbtnGoToPage2_C lick(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles lbtnGoToPage2.C lick
Response.Redire ct("TestPage2.a spx", False)
End Sub

'aspx #2
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Response.Write( "Hello World") 'breakpoint here reveals .Int1 member =
567, regardless of session call in aspx #1
End Sub

Jan 23 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1410
by: .net lear | last post by:
if I have an object, say a recipe, which is added to a database, whose responsibility is it to add to the db? The recipe or something else? Let's say I want to delete a recipe? Does the recipe kill itself? Or does the database or something else do the removal? Where does the responsibility lie? Thanks.
5
2133
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework or something that completely abstracts you from the persistence details. Are you: 1. Having simple data type interfaces and the data layer know nothing about the domain models. For example: public int SaveCustomer( string fname, string...
10
387
by: Simon Harvey | last post by:
Hi everyone, Can anyone tell me if I declare a global variable in my pages code behind, is it persisted if the page does a post back, or do I need to add the object to the session object in order to persist it. Is the session the best mechnism for persisiting this object Thanks everyone
4
1589
by: Marcel Balcarek | last post by:
Hello, I have a page (page1.aspx) that builds some complex .NET objects. I successfully pass these objects to another different window (page2.aspx). How can I persist these objects on a POST back of the same window (page2.aspx)? Thank you Marcel
13
1884
by: Mark Anthony Spiteri | last post by:
Hi, I am designing an ASP.NET application in which particular pages require global variables that need to be persisted during postbacks. What is the best practice to do this? Is it to use the viewstate object or is declaring the variables as static sufficient (I am currently using this method)? Thank you,
2
1827
by: Eric Cathell | last post by:
I am using dOOdads as my persistence layer. I have a business object Person that sits in a Project called DOMAIN I have 2 dOOdads in a project called BLL. one is _Person and is declared MustInherit the other is Person and is my concrete class. My main goal of BLL.Person is to protect custom methods and properties against regeneration.
8
1402
by: Casper | last post by:
Hi, i read several articles about serialization. I know now that it is a process of converting an object into a stream of data so that it can be is easily transmittable over the network or can be continued in a persistent storage location. Now i did some tests in order to understand it better: I first executed the code below (this (summarized) code produces a virtual simple shopping cart which is put in the Profile of the user) with...
20
4042
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This tells me if a variable has changed, give me the original and current value, and whether the current value and original value is/was null or not. This one works fine but is recreating the same methods over and over for each variable type. ...
22
2158
by: Neil Gould | last post by:
Or... when is a script not a script? I have several modules for managing different aspects of our club's website, most of which are multi-page. Does setting such things as server.ScriptTimeout or response.buffer values at the start of the first page persist throughout the session, or are they "reset" with each function or sub, etc.? TIA.
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.