Declaring variables with global scope (Newbie Question)!

M

Mortal Wombat

Hi,

I am a beginner VB.NET developer and am trying to create my first ASP.NET
web application. I know that in a standard Windows Form type application, if
I want to declare a particular variable as global, then I declare it in a
separate module... any variables then declared in that module will be
available to any form within the application. How can I achieve the same
thing in an ASP.NET application?
I wish to declare a few variables that have scope beyond one WebForm page,
so that I can use the variable in other WebForm pages within the
application.

I suspect it is something to do with the global.asax file, but I cannot find
a reference for the correct way to do it.

Many thanks in advance,

MW
 
K

Kevin Spencer

"Global" is a kind of different concept in ASP.Net than in Windows Forms. In
a Windows Form, all of the components of the form reside in the same
persistent memory space on the same machine. In ASP.Net, you're talking
about a client-server app with memory space on the client, and separate
memory spaces on the server for each client (Session State), as well as
memory space for the entire server application (Application State), and
other places as well where you can cache things with varying kinds of scope.

If you're talking strictly about the server component of the app, you can
store data which is global to the entire app in Application State, or in
static objects in your heap, as well as in storage media, such as files and
database. If you want to store data that is global to a single client
Session, but across all pages, you can store it in Session State, or in
Cookies, which actually reside on the Client, but are transmitted to the
server with each Request.

The global.asax class contains a number of event handlers which you can use
to store such data at the beginning of the Application LifeCycle, at the
beginning of a user Session, and others.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 
K

Kevin Spencer

John makes a good point. When deciding on the scope af any variable, it
should be as small as necessary, in order to avoid any possible conflicts.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 
M

Mortal Wombat

Thanks for all your responses, I will investigate everything you mentioned
to see which option I should use.
Thanks!

MW
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top