Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 28th, 2005, 02:43 PM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default HOW-TO Maintain a Class Object in Session

Hello All,

My background is in JSP and am having problem understand ASP.Net.

I am trying to maintain a class instance throughtout a session. I instantiated a class in the code-behind of an aspx. How can I refer to this instance from other aspx pages (i.e. using the same class instance instead of create a new one)?

Thanks!

  #2 (permalink)  
Old April 28th, 2005, 09:21 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Put the class instance in the session collection, then retrieve it when you need to use it.

vb:
Session("myClassInstance") = myClass
...
myClass = CType(Session("myClassInstance"), MyClassType)

c#:
Session["myClassInstance"] = myClass;
...
myClass = (MyClassType)Session["myClassInstance"];


-Peter


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to maintain session between Domain &subdomain im.imrankhan PHP How-To 1 September 5th, 2008 12:44 PM
Maintain the session in asp.net samgaya1983 ASP.NET 2.0 Professional 2 June 29th, 2007 03:37 AM
Database Session Class sw8370 Pro PHP 0 February 4th, 2006 12:19 PM
Accessing Session variables from custom class mohyneenm ASP.NET 1.0 and 1.1 Professional 2 January 26th, 2005 07:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.