accessing global class from other pages

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
 
D

Daves

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

Juan T. Llibre

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

???
 
D

Daves

that certainly "cleans" the preexisting string but I need to be able to use
the += in content pages!
 
M

Matt Berther

Hello Daves,

I'm guessing that you created the Title field as static. A static field will
be around until the HttpApplication dies.
 
D

Daves

that explains!
does that apply to all static fields I would create, not only in
global.asax?
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top