By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,507 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

Problems with public variables

P: n/a
Hi everyone,

I'm trying to use public variables in a web form to hld specific values.
What happens is that the public variables (declared as public x as y in the
beginning of the class), doesn't seem to hold the value from function call
to function call.

Does anyone can help me abou this?

best regards

JM
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
They won't, every time a postback occurs on the page, they'll be reset.
Using Public Variables in any context isn't probably a good idea...you can
use a class in general with Static or shared properties depending on your
prog language. However, in ASP.NET, a module for instance will be shared
among ALL Users which is seldom desireable.

Instead, store things in Session Variables. They give you the same effect
as public, are isolated to the session and can be strongly typed. The best
of all worlds.

Session("SomeNameForAVariable") = someObject

Dim someNewObject as someObject
someNewObject = CTYpe(Session("SomeNameForAVariable"), someObject)

You can hit this from any page in your app.
HTH,

Bill
"Jose Meireles" <jm*******@myconnections.biz> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi everyone,

I'm trying to use public variables in a web form to hld specific values.
What happens is that the public variables (declared as public x as y in the beginning of the class), doesn't seem to hold the value from function call
to function call.

Does anyone can help me abou this?

best regards

JM

Jul 21 '05 #2

P: n/a
Thanks for your anwer Bill,

I've solve my problem using public variables in a module but I wasn't aware
about the fact the public or shared variables in a class/module would be
shared across the entire application (for every sessions). Thats an
important issue to consider.

Thanks again

Jose

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:u8*************@TK2MSFTNGP11.phx.gbl...
They won't, every time a postback occurs on the page, they'll be reset.
Using Public Variables in any context isn't probably a good idea...you can
use a class in general with Static or shared properties depending on your
prog language. However, in ASP.NET, a module for instance will be shared
among ALL Users which is seldom desireable.

Instead, store things in Session Variables. They give you the same effect
as public, are isolated to the session and can be strongly typed. The best of all worlds.

Session("SomeNameForAVariable") = someObject

Dim someNewObject as someObject
someNewObject = CTYpe(Session("SomeNameForAVariable"), someObject)

You can hit this from any page in your app.
HTH,

Bill
"Jose Meireles" <jm*******@myconnections.biz> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi everyone,

I'm trying to use public variables in a web form to hld specific values.
What happens is that the public variables (declared as public x as y in

the
beginning of the class), doesn't seem to hold the value from function call to function call.

Does anyone can help me abou this?

best regards

JM


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.