Ron's Sandbox

Global Variables

Monday, 5 May 2008 14:54 by hagermanr

I do a lot of asp.net development and what I remember most from my VB 6 days (traditional asp) is the session variable.  In short you had variables that held session data to be used on multiple websites.

In the .NET 2.0 world, I’ve learned to move away from session variables and on to global variables. When you run a project that references a DLL, it loads that DLL into memory and it stays there for the duration of the users session. So if you have a DLL in your web application and you want to remember a value, say a BEMS ID, you can create a global variable. In your class library, have a class for your global variables and add public static string gMyVariable = “”; or public static int gMyIntValue; whatever the case may be. Then in your web page code-behind, you can reference that global variable.

if (clsGlobals.gMyVariable == "")
      Response.Write("Nothing there");
else
      Response.Write("Value is: " + clsGlobals.gMyVariable);

Pretty simple. Once your session times out or you destroy the object, memory is cleared and the variable is gone.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading