Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 3rd, 2004, 03:38 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default 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\">
  #2 (permalink)  
Old August 3rd, 2004, 04:58 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cairo, , Egypt.
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

each instanse of the webform1 class has its own variables

Ahmed Ali
Software Developer
  #3 (permalink)  
Old August 4th, 2004, 12:31 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ahmed Ali,you didn't answer me,my question is about something else...
Thanks anyway.

--------------------------------------------
Mehdi.:)
  #4 (permalink)  
Old August 4th, 2004, 02:08 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

>>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.:)
  #5 (permalink)  
Old August 4th, 2004, 08:01 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

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.
  #6 (permalink)  
Old August 4th, 2004, 08:18 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
  #7 (permalink)  
Old August 4th, 2004, 11:32 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Peter thank you,
can you tell me what is The application collection?
can I use assembly(i.e GAC)?

--------------------------------------------
Mehdi.:)
  #8 (permalink)  
Old August 4th, 2004, 02:05 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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>"
  #9 (permalink)  
Old August 4th, 2004, 11:33 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you Peter.

--------------------------------------------
Mehdi.:)
  #10 (permalink)  
Old August 7th, 2004, 11:31 PM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is Global.aspx for ASP.net 2.0 jdang67 ASP.NET 2.0 Basics 2 June 2nd, 2009 03:40 AM
How to use global dataset for asp.net application swati_joshi ASP.NET 1.0 and 1.1 Basics 3 April 6th, 2007 09:30 PM
Global Variables in .NET mbmsecret C# 5 July 6th, 2004 02:27 AM
Global variables ps124 ASP.NET 1.0 and 1.1 Basics 6 April 6th, 2004 02:48 PM



All times are GMT -4. The time now is 01:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.