simple variable scope question

  • Thread starter Thread starter mattdaddym
  • Start date Start date
M

mattdaddym

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.
 
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
 
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top