accessing global class from other pages

  • Thread starter Thread starter Daves
  • Start date Start date
D

Daves

can anyone imagine why I cannot access static variables in my global class
from other pages, eg:
myNumber = myGlobal.UserID;

where global.asax contains:
<%@ Application Language="C#" Classname="myGlobal" %>
<script runat="server">
public static int UserID = 0;
void Session_Start(Object sender, EventArgs e)
{...}

It doesn't work either using
myNumber = Global.UserID;

btw I'm using .Net 2.0
 
actually I CAN access it using
myString = ASP.myGlobal.Title;

but what's odd is that it's content lives between page cycles so if I do
ASP.myGlobal.Title += "testing... "

and refresh page the string becomes
"testing... testing... testing..." etc!
 
What happens if you just set myGlobal.Title string :
ASP.myGlobal.Title = "testing2... "

instead of adding to the existing myGlobal.Title string :
ASP.myGlobal.Title += "testing... "

???



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
that certainly "cleans" the preexisting string but I need to be able to use
the += in content pages!
 
Hello Daves,

I'm guessing that you created the Title field as static. A static field will
be around until the HttpApplication dies.
 
that explains!
does that apply to all static fields I would create, not only in
global.asax?
 
Back
Top