Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic 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
 
Old February 20th, 2004, 03:23 PM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Berni016x
Default self made objects saved in session-variables

hello!

As i know there is a possibility to save objects in session-variables.
why does the following not work?
Class myClass
....
End Class

Dim oMyClass = New MyClass
Set Session("myObj") = oMyClass

this code only works within one page. if i try to use the object at an other page it doesn't work. the methods of the object couldn't be found.

does this only works with code like this:
Set Session("myObj") = Server.CreateObject("something.myObj")
this would be very bad! what should i do then?

Can please anybody help me??? PLEASE!
thx Bernhard
:(


same in german:

Hallo!

Man müsste doch Objekte in Session-Variablen speichern können!
Warum funktionierts dann nicht?

Class myClass
....
End Class

Dim oMyClass = New MyClass
Set Session("myObj") = oMyClass

Das funktioniert nur innerhalb einer Seite! Wenn ich dieses Objekt auf einer anderen Seite verwenden möchte wirds zwar als Objekt erkannt, es funktioniert jedoch nicht! --> Es werden keine Methoden oder dergleichen erkannt!

Kann es sein, dass dies nur mit vorkompilierten Objekten funktioniert?
Also:
Set Session("MyObj") = Server.CreateObject("irgendwas.was")

Wenn ja... sch*** was mach ich dann???

Kann mir bitte jemand helfen?
thx
Bernhard
:(

 
Old February 23rd, 2004, 09:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My suggestion:
Instatiate the class on each page (eg by storing the class definition in an include file). If you need to pass information to the constructor, then store that in session variables (or a single session level array).

Otherwise, create a COM component.

Cheers
Ken

Microsoft MVP - Windows Server (IIS)
www.adOpenStatic.com
 
Old February 23rd, 2004, 10:53 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
Default

It looks like you're trying to mix client-side script with server-side script and perhaps confusing classes with session variables. If you have a value for MyClass then why don't you just try this.

Session("myObj") = MyClass

Better Yet...

Session("MyClass") = MyClass

Unless you are reseting Session("MyClass") on another page, this session variable will stay alive as long as the session is alive.
I thought that this would work with objects as well, but don't redefine the object once it's created.

Hope this helps.
 
Old February 23rd, 2004, 10:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In addition classes created in script only exist for as long as the page so saving then in Session variables won't work. Any COM class, unless free threaded, will also slow your server down if stores in a Session variable. This means any COM class created in VB.

--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing objects in Session variables mega ASP.NET 1.0 and 1.1 Basics 8 November 16th, 2004 02:38 PM
Accessing application objects from session EJBs enghoe BOOK: Expert One-on-One J2EE Design and Development 0 January 7th, 2004 02:36 AM
session variables help face Classic ASP Databases 4 September 12th, 2003 03:57 PM
Why is it bad to put Objects into Session Vars? treycarroll Beginning PHP 3 August 18th, 2003 12:44 PM





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