Problems with public variables

  • Thread starter Thread starter Jose Meireles
  • Start date Start date
J

Jose Meireles

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

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