Global declaration of a class object

Last post 10-10-2007 4:55 PM by Andrey1. 2 replies.

Sort Posts:

  • Global declaration of a class object

    10-10-2007, 3:15 PM
    • Loading...
    • nrlahoti
    • Joined on 10-09-2007, 5:19 PM
    • Posts 2

     I want to create an instance of a Class. The problem is that i want to create this instance once when the session starts and i should have access to this instance in  my all other .aspx pages. Can anyone suggest where i should create this instance so that it will be available on all .aspx pages?

    Thanks.

  • Re: Global declaration of a class object

    10-10-2007, 3:30 PM
    Answer
    • Loading...
    • pkellner
    • Joined on 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,435
    • Moderator
      TrustedFriends-MVPs

    take a look at this for an example:

    nrlahoti:
    access to this instance in  my all other .aspx pages

    http://www.odetocode.com/Articles/89.aspx

     

     

     

    Peter Kellner
    http://73rdstreet.com and blogging at
    http://PeterKellner.net
    MVP, ASP.NET
  • Re: Global declaration of a class object

    10-10-2007, 4:55 PM
    Answer
    • Loading...
    • Andrey1
    • Joined on 09-19-2007, 11:45 AM
    • Posts 171

    However being not considered as a good practice, you can either create a startup page that will always load first, or use Global.asax file as the previous poster had suggested, and then use the Session object to put some value inside of it. It works like that:

    HttpContext.Session["SomeKey"] = YourObject

    And it will be accessible across all page in your application.

    HTH,
    Andrey.

Page 1 of 1 (3 items)
Microsoft Communities
Page view counter