 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 3rd, 2004, 03:38 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Global Variables in ASP.NET
I have a simple but important question...
suppose in my webform class I declare a static variable like
static int a=0;
and then I put my application in server now for example we have four users hitting my site...is this integer variable unique for all these four users?..does it mean if one user changes this variable it changes for other users?
Thanks in Advance :)
--------------------------------------------
Mehdi.
__________________
_____________
<font color=\"teal\"><font size=\"1\"><b>Mehdi.
software student.</b></font id=\"size1\"></font id=\"teal\">
|
|

August 3rd, 2004, 04:58 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
each instanse of the webform1 class has its own variables
Ahmed Ali
Software Developer
|
|

August 4th, 2004, 12:31 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Ahmed Ali,you didn't answer me,my question is about something else...
Thanks anyway.
--------------------------------------------
Mehdi.:)
|
|

August 4th, 2004, 02:08 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
>>does it mean if one user changes this variable it changes for other users?
is this a right thought?(I think yes because it is static,what is your opinion?)
--------------------------------------------
Mehdi.:)
|
|

August 4th, 2004, 08:01 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
dear Mehdi plz take a look at this http://p2p.wrox.com/topic.asp?TOPIC_ID=2064, if u mean in code-behind pages.
we discuss about it alot & friends helped me there much.
Always:),
Hovik Melkomian.
|
|

August 4th, 2004, 08:18 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Mehdi,
Each page is executed separately, within its own context. Two page executions happening simultaneously are not related in any way apart from their existance within the same application. Only during the execution of one page, in one page's context will the same "current" value in a class' public static variable be visible.
Let us say that you have this:
Public Class MyClass
Public Static MyStaticVariable As Integer = 0
End Class
User A:
MyClass.MyStaticVariable=1
Response.Write(MyClass.MyStaticVariable) 'This prints "1"
User B:
Response.Write(MyClass.MyStaticVariable) 'This prints "0"
If you need to save an application-wide value so that all users can see the same value, you need to save it to some persistant or semi-persistant medium. This usually means:
A) A file
B) A database
C) The application collection
|
|

August 4th, 2004, 11:32 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Peter thank you,
can you tell me what is The application collection?
can I use assembly(i.e GAC)?
--------------------------------------------
Mehdi.:)
|
|

August 4th, 2004, 02:05 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Stay away from the GAC.
I'm just talking about the application name/value collection. It's used just like the session, but it's visible to all users of the application.
Application.Item("<key name>") = "<value>"
|
|

August 4th, 2004, 11:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Thank you Peter.
--------------------------------------------
Mehdi.:)
|
|

August 7th, 2004, 11:31 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Ok application is a global variable & its fine. but why & how u r going to use it. Application object take too many resorses & if u use it for not required things it might not be good for Server. be aware of that!
I was in holiday sorry for my delay!
Always:),
Hovik Melkomian.
|
|
 |