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

simple variable scope question

Hi, I have a variable question in regards to my asp .net page.

I need to declare a variable whose value is readable/writable to all
of the subroutines of a specific page. So far I have one of two
problems.

The first is if I declare my variable right after the class
definition, then I can use it anywhere, but the value does not persist
from one subroutine to the next.

The second is if I declare the variable as shared right after the
class definition, then I can use the value anywhere, but if I have 2
users, on two different computers, then they are accessing the same
values. I don't want this to happen.

Can this be done without using sessionstate? Thanks all.

Apr 12 '07 #1
2 1244
A Page is an instance of the class System.Web.UI.Page, so you can declare a
Field in your code, and that will be globally accessible within the Page.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

<ma********@gmail.comwrote in message
news:11**********************@w1g2000hsg.googlegro ups.com...
Hi, I have a variable question in regards to my asp .net page.

I need to declare a variable whose value is readable/writable to all
of the subroutines of a specific page. So far I have one of two
problems.

The first is if I declare my variable right after the class
definition, then I can use it anywhere, but the value does not persist
from one subroutine to the next.

The second is if I declare the variable as shared right after the
class definition, then I can use the value anywhere, but if I have 2
users, on two different computers, then they are accessing the same
values. I don't want this to happen.

Can this be done without using sessionstate? Thanks all.

Apr 12 '07 #2
On Apr 12, 1:18 pm, "Kevin Spencer" <unclechut...@nothinks.comwrote:
A Page is an instance of the class System.Web.UI.Page, so you can declare a
Field in your code, and that will be globally accessible within the Page.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net

<mattdad...@gmail.comwrote in message

news:11**********************@w1g2000hsg.googlegro ups.com...
Hi, I have a variable question in regards to my asp .net page.
I need to declare a variable whose value is readable/writable to all
of the subroutines of a specific page. So far I have one of two
problems.
The first is if I declare my variable right after the class
definition, then I can use it anywhere, but the value does not persist
from one subroutine to the next.
The second is if I declare the variable as shared right after the
class definition, then I can use the value anywhere, but if I have 2
users, on two different computers, then they are accessing the same
values. I don't want this to happen.
Can this be done without using sessionstate? Thanks all.
I don't understand how to "declare a field" in my code. Although, I
solved the issue by using some invisible controls on the page. I guess
this accomplishes what you are saying in its own way, though. Seems it
would be cleaner to do declare it in the code, though. Thanks for your
help.

Apr 17 '07 #3

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

Similar topics

3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
15
by: Alex | last post by:
could somebody tell me the difference between those two styles: function abc(var1, var2){ /* logic in here */ } and abc = function(var1, var2){ /* logic in here */ }; When / why would I...
12
by: Jeff B. | last post by:
If an object implements the IDisposable interface, should I always call the Dispose method or is just setting it to null and letting the GC handle it sufficient? Here is the pattern I've been...
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...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
3
by: Ryan Pedersen | last post by:
I have a small program that executes a single very long running background thread today. The scope of all variables in the method that is running in this thread today are all local to the...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
5
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
26
by: optimistx | last post by:
A variable in global scope var a1 = 'contents of global variable a1'; can be references (with some limitations) as window; // or window.a1; // or even window;
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
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:
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.