Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > accessing global class from other pages

Reply
Thread Tools

accessing global class from other pages

 
 
Daves
Guest
Posts: n/a
 
      03-20-2005
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


 
Reply With Quote
 
 
 
 
Daves
Guest
Posts: n/a
 
      03-20-2005
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!


 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      03-21-2005
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...
======================

"Daves" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!
>



 
Reply With Quote
 
Daves
Guest
Posts: n/a
 
      03-21-2005
that certainly "cleans" the preexisting string but I need to be able to use
the += in content pages!

"Juan T. Llibre" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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...
> ======================
>
> "Daves" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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!
>>

>
>



 
Reply With Quote
 
Matt Berther
Guest
Posts: n/a
 
      03-21-2005
Hello Daves,

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

--
Matt Berther
http://www.mattberther.com

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




 
Reply With Quote
 
Daves
Guest
Posts: n/a
 
      03-21-2005
that explains!
does that apply to all static fields I would create, not only in
global.asax?

"Matt Berther" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). com...
> Hello Daves,
>
> I'm guessing that you created the Title field as static. A static field
> will be around until the HttpApplication dies.
>
> --
> Matt Berther
> http://www.mattberther.com
>
>> 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!

>
>
>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      03-21-2005
On Mon, 21 Mar 2005 14:51:23 -0000, "Daves" <(E-Mail Removed)> wrote:

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


Yes - all fields marked as static behave the same way.

--
Scott
http://www.OdeToCode.com/blogs/scott/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialize global variable before any other global variables jubelbrus C++ 5 07-20-2007 06:38 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Accessing components on other pages CJ ASP .Net 3 12-09-2005 03:20 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM



Advertisments