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

Can I use static variable in the scope of a PAGE?

I m building an application in which I redirect the user to a particular
page. In the Page Load event of the that page , I assign a variable
some value. Then I call the Button click event on that page. I have
applied the !IsPostBack so that the Page Load event does not occur on
clicking the button. Now the problem is that I want to use the value of
that variable which i was population on Page Load event.
Can I use that variable as static?
I have a doubt in my mind that as I am simply redirecting the users to
that page, the value of that variable could be set to some another value
if another user is redirected to that page as the variable is static.
Please help me to clarify my concept.
Thanks,
Sandeep
Apr 21 '06 #1
4 1221
A static variable in a class is shared by all instances of that class. If
you want to persist the variable, put it into ViewState.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Sandeep Singh" <ef*****@newsgroups.nospam> wrote in message
news:uu**************@TK2MSFTNGP02.phx.gbl...
I m building an application in which I redirect the user to a particular
page. In the Page Load event of the that page , I assign a variable some
value. Then I call the Button click event on that page. I have applied the
!IsPostBack so that the Page Load event does not occur on clicking the
button. Now the problem is that I want to use the value of that variable
which i was population on Page Load event.
Can I use that variable as static?
I have a doubt in my mind that as I am simply redirecting the users to
that page, the value of that variable could be set to some another value
if another user is redirected to that page as the variable is static.
Please help me to clarify my concept.
Thanks,
Sandeep

Apr 21 '06 #2
> A static variable in a class is shared by all instances of that class. If you
want to persist the variable, put it into ViewState.

Or into Session
--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Sandeep Singh" <ef*****@newsgroups.nospam> wrote in message
news:uu**************@TK2MSFTNGP02.phx.gbl...
I m building an application in which I redirect the user to a particular
page. In the Page Load event of the that page , I assign a variable some
value. Then I call the Button click event on that page. I have applied the
!IsPostBack so that the Page Load event does not occur on clicking the
button. Now the problem is that I want to use the value of that variable
which i was population on Page Load event.
Can I use that variable as static?
I have a doubt in my mind that as I am simply redirecting the users to that
page, the value of that variable could be set to some another value if
another user is redirected to that page as the variable is static. Please
help me to clarify my concept.
Thanks,
Sandeep

Apr 21 '06 #3
Well, there are several caching mechanisms available, but if it is
apage-scoped variable of a primitive type, the most efficient place would be
the ViewState. I didn't want to confuse the OP at this point (unless it
became necessary!)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:mn***********************@spamgourmet.com...
A static variable in a class is shared by all instances of that class. If
you want to persist the variable, put it into ViewState.


Or into Session
--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Sandeep Singh" <ef*****@newsgroups.nospam> wrote in message
news:uu**************@TK2MSFTNGP02.phx.gbl...
I m building an application in which I redirect the user to a particular
page. In the Page Load event of the that page , I assign a variable some
value. Then I call the Button click event on that page. I have applied
the !IsPostBack so that the Page Load event does not occur on clicking
the button. Now the problem is that I want to use the value of that
variable which i was population on Page Load event.
Can I use that variable as static?
I have a doubt in my mind that as I am simply redirecting the users to
that page, the value of that variable could be set to some another value
if another user is redirected to that page as the variable is static.
Please help me to clarify my concept.
Thanks,
Sandeep


Apr 21 '06 #4
Hi Sandeep,

I agree with other members' suggestion. Static variables in .net is shared
based on AppDomain scope, and as for ASP.NET application, each application
running inside its own AppDomain , that means static variables are
appication wide variables. So for your page level code, I suggest you
considering using other storage like SessionState, or the Profile Service...

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Apr 24 '06 #5

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

Similar topics

6
by: pembed2003 | last post by:
Hi all, I am reading the book "C++ How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
16
by: RB | last post by:
Hi clever people :-) I've noticed a lot of people stating not to use static variables with ASP.NET, and, as I understand it, the reason is because the variable is shared across user sessions -...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.