accessing global class from other pages

Discussion in 'ASP .Net' started by Daves, Mar 20, 2005.

  1. Daves

    Daves Guest

    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
    Daves, Mar 20, 2005
    #1
    1. Advertising

  2. Daves

    Daves Guest

    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!
    Daves, Mar 20, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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!
    >
    Juan T. Llibre, Mar 21, 2005
    #3
  4. Daves

    Daves Guest

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

    "Juan T. Llibre" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    >> 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!
    >>

    >
    >
    Daves, Mar 21, 2005
    #4
  5. Daves

    Matt Berther Guest

    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!
    Matt Berther, Mar 21, 2005
    #5
  6. Daves

    Daves Guest

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

    "Matt Berther" <> wrote in message
    news:...
    > 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!

    >
    >
    >
    Daves, Mar 21, 2005
    #6
  7. Daves

    Scott Allen Guest

    On Mon, 21 Mar 2005 14:51:23 -0000, "Daves" <> 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/
    Scott Allen, Mar 21, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CJ
    Replies:
    3
    Views:
    613
    John Timney \( MVP \)
    Dec 9, 2005
  2. E11
    Replies:
    1
    Views:
    4,736
    Thomas Weidenfeller
    Oct 12, 2005
  3. Erik Wikström
    Replies:
    1
    Views:
    311
    Mike Wahler
    Oct 7, 2003
  4. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Decralation of class inside other class and definition outside this class

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 13, 2007, in forum: C++
    Replies:
    2
    Views:
    336
    Alf P. Steinbach
    Jul 13, 2007
  5. jubelbrus
    Replies:
    5
    Views:
    608
    JohnQ
    Jul 20, 2007
Loading...

Share This Page