Q: define values for all pages

G

Guest

Hello,
In my C# asp.net web application, I need to define a few variable that is
reachable from all pages. If it was C I would define it in the .h file as
struct and use it in the myStruct.myFirstvalie, MyStruct.SecondValue, how
should I do this here in asp.net? I guess I should use class, can you give me
example to handle it.?
 
G

Guest

Create one .cs file with in the project. Define all the variables that are
required all the variables.

Then in the .aspx.cs pages call the variables by creating objects to those
classes.

Eg:
Temp dt = new Temp();
dt.newtest();
string Name = dt.Name;

Where temp is the class created.
 
T

Tom.PesterDELETETHISSS

You got a few options. If you want the scope of the variable to be just the
execution of the page you can place a class in the bin directory (or app_code
in version asp.net2).
That class will be available to all of your asp.net pages and you can make
the varaible static if you don't want to instantiate the class.
You could also make the page class inherit a customized base class so that
it would appear that the variable is 'native' just like the request,response,...
obejct.

If you want that variable to remember its value between page request than
you have to use the session object if you want the scope of the variable
to bo 1 user.
Use the application object if you want the varaible to be seen and modifiable
by all users .

Let me know if you have any more questions..

Cheers,
Tom Pester
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top