473,394 Members | 1,867 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,394 software developers and data experts.

ASP.NET Page Variables Persistence

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,

Mark Anthony Spiteri

Nov 18 '05 #1
13 1856
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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)?


You'll need to use the ViewState object, or perhaps the Session
object. A static variable isn't enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth
Nov 18 '05 #2
Thank you for your reply.

"Gareth Jones" wrote:
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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)?


You'll need to use the ViewState object, or perhaps the Session
object. A static variable isn't enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth

Nov 18 '05 #3
Thank you for your reply

"Gareth Jones" wrote:
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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)?


You'll need to use the ViewState object, or perhaps the Session
object. A static variable isn't enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth

Nov 18 '05 #4
Thank you for your reply.

"Gareth Jones" wrote:
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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)?


You'll need to use the ViewState object, or perhaps the Session
object. A static variable isn't enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth

Nov 18 '05 #5
Thank you for your reply

"Gareth Jones" wrote:
On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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)?


You'll need to use the ViewState object, or perhaps the Session
object. A static variable isn't enough - in a web environment the
application is restarted for every request, so your static variables
are being reinitialised.

Gareth

Nov 18 '05 #6
Are the values of the page global variables supposed to be the same
for all of the users who visit the page?

--
Scott
http://www.OdeToCode.com

On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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,

Mark Anthony Spiteri


Nov 18 '05 #7
No,

each user will have different variable values. Thus making use of the Application Object is futile.

"Scott Allen" wrote:
Are the values of the page global variables supposed to be the same
for all of the users who visit the page?

--
Scott
http://www.OdeToCode.com

On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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,

Mark Anthony Spiteri


Nov 18 '05 #8
Yes, this also rules out using static variables. As suggested, Session
state and Viewstate are both options.

--s

On Sun, 27 Jun 2004 09:05:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
No,

each user will have different variable values. Thus making use of the Application Object is futile.

"Scott Allen" wrote:
Are the values of the page global variables supposed to be the same
for all of the users who visit the page?

--
Scott
http://www.OdeToCode.com

On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
>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,
>
>Mark Anthony Spiteri



--
Scott
http://www.OdeToCode.com
Nov 18 '05 #9
Are the values of the page global variables supposed to be the same
for all of the users who visit the page?

--
Scott
http://www.OdeToCode.com

On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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,

Mark Anthony Spiteri


Nov 18 '05 #10
No,

each user will have different variable values. Thus making use of the Application Object is futile.

"Scott Allen" wrote:
Are the values of the page global variables supposed to be the same
for all of the users who visit the page?

--
Scott
http://www.OdeToCode.com

On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
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,

Mark Anthony Spiteri


Nov 18 '05 #11
"Mark Anthony Spiteri" <mark@[remove]mspiteri.com> wrote in message
news:76**********************************@microsof t.com...
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)?

Use ViewState if you need the variables to persist for multiple postbacks to
the same page. Use Session state if you need longer persistence.

Using static variables is almost always wrong, as they will be shared
amongst users. They will also have to be synchronized if written to because
multiple requests may access them at the same time.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #12
Yes, this also rules out using static variables. As suggested, Session
state and Viewstate are both options.

--s

On Sun, 27 Jun 2004 09:05:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
No,

each user will have different variable values. Thus making use of the Application Object is futile.

"Scott Allen" wrote:
Are the values of the page global variables supposed to be the same
for all of the users who visit the page?

--
Scott
http://www.OdeToCode.com

On Sat, 26 Jun 2004 08:08:01 -0700, "Mark Anthony Spiteri"
<mark@[remove]mspiteri.com> wrote:
>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,
>
>Mark Anthony Spiteri



--
Scott
http://www.OdeToCode.com
Nov 18 '05 #13
"Mark Anthony Spiteri" <mark@[remove]mspiteri.com> wrote in message
news:76**********************************@microsof t.com...
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)?

Use ViewState if you need the variables to persist for multiple postbacks to
the same page. Use Session state if you need longer persistence.

Using static variables is almost always wrong, as they will be shared
amongst users. They will also have to be synchronized if written to because
multiple requests may access them at the same time.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #14

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

Similar topics

6
by: Paolo Losi | last post by:
Hi all, I'm pretty new to the python language so please excuse me if this is FAQ... I'm very glad to be part of the list! :-) I'm looking into a way to implement a generic workflow framework...
4
by: ketulp_baroda | last post by:
Hi Global variables are not truly global in Python ; they are only global within a module namespace. I want a variable such that if i change its value in any module then it should be reflected in...
2
by: Brad | last post by:
Hi everyone, I've been using ASP on a few different projects over the past year, either using Javascript or VBScript. During that time, I've made use of session variables, but even then, I've...
27
by: Mr. Ed | last post by:
This should be easy, but I can't immediately see what the answer is... I have some code which needs to be re-entrant. It also needs to create a unique identifier. The obvious way to create a...
5
by: Diffident | last post by:
Hello All, I have written a webform which is by default derived from "Page" class. I have coded another utility class with few methods and an object of this class is instantiated from the webfom...
7
by: Steve Mauldin | last post by:
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...
2
by: dkode | last post by:
Hello, I am laying out the architecture for a very large website that will scale to a very large degree. I have a couple of questions before I attempt to go and implement a Broker/Persistence...
2
by: Richard Carpenter | last post by:
I have a four-page tabcontrol with a gridview on each page. I have the primary key column of each gridview set to hidden (visible = false), but it still shows up on all but the first page. Anyone...
0
myusernotyours
by: myusernotyours | last post by:
Hi all, Am trying to create a Java Desktop App that uses Java Persistence in Netbeans. The database is MS Access but I tried with Mysql and got the same error. When I run the app( Create the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...

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.