web application using Visual Basic.NET

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I have two programs which are supposed to function the
same way. The first is a windows application, and the
second is supposed to be a web application. The windows
application works perfectly. The web application does
not. I used the same code with minimal changes. I have a
list of global variables defined. They are then
initialized when the page is loaded for the first time.
As I step through the program, this process works
correctly. However, when I try to use one of those global
variables in another function, all of a sudden it carries
a value of "Nothing". I have no idea why it doesn't still
carry the value it was initialized with. Is there some
trick to web-based programs that I'm missing?
 
Declare the global variables as Shared rather than with
the Dim statement. Apparently there is something with the
refresh in a web application that resets the variables
unless they are Shared, which allows the variables to hold
their value until the entire application is closed.
 
Tim:

Many variables get reset on a post back, so you may want to store them in
session variables instead.

To Create a Session variable

Session("MyVariable") = somevalue

To REtreive it someotherValue = CType(Session("MyVariable"),VariableType)

That should do it for you.

Let me know if you have any troubles.

Bill
 
Back
Top