469,358 Members | 1,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

How to access an object variable in global.asax.vb from a page?

I have the following code in global.asax.vb

Public UO As UNIOBJECTSLib()

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

UO = new UniObjectsLib()

End Sub

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

' Fires when the application is started

Application("MyObj") = UO

End Sub

How can I retrieve this UO obj from a page?

thanks


Nov 18 '05 #1
6 4335
"dbui" <nn*****@hotmail.com> wrote in news:#E9iN4bbEHA.3684
@TK2MSFTNGP09.phx.gbl:
Application("MyObj") = UO

How can I retrieve this UO obj from a page?


Dim SomeVariable as MyObj = Application("MyObj")

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #2
thanks Tam,

I did try that b4 posting the question and it didn't work. It gave me an
error, something like "Object instance was not set..."
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"dbui" <nn*****@hotmail.com> wrote in news:#E9iN4bbEHA.3684
@TK2MSFTNGP09.phx.gbl:
Application("MyObj") = UO


How can I retrieve this UO obj from a page?


Dim SomeVariable as MyObj = Application("MyObj")

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #3
I think what you meant as followed:

Dim obj as MyObject = Ctype(Application("MyObj") , MyObject)

I tried that and got an error : "Server throws error exception." .

thanks

"Tampa .NET Koder" <Ta***********@discussions.microsoft.com> wrote in
message news:8D**********************************@microsof t.com...
Try

Dim obj as New MyObject

obj = Ctype(Application("MyObj") , MyObject)

It is key to use the NEW opeator to create objects in memory, otherwise you will get this error
"dbui" wrote:
thanks Tam,

I did try that b4 posting the question and it didn't work. It gave me an
error, something like "Object instance was not set..."
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"dbui" <nn*****@hotmail.com> wrote in news:#E9iN4bbEHA.3684
@TK2MSFTNGP09.phx.gbl:

> Application("MyObj") = UO
>

>
> How can I retrieve this UO obj from a page?

Dim SomeVariable as MyObj = Application("MyObj")

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 18 '05 #4
"dbui" <nn*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have the following code in global.asax.vb

Public UO As UNIOBJECTSLib()
First, never use public fields.

Private _UO As New UNIOBJECTSLib()
Public Sub New()
MyBase.New()

'This call is required by the Component Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

UO = new UniObjectsLib()
You don't need the above, since I used New in the declaration.
End Sub

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

' Fires when the application is started

Application("MyObj") = _UO

End Sub

How can I retrieve this UO obj from a page?


Public Property UO As UNIOBJECTSLib
Get
Return DirectCast(Application("MyObj"), UNIOBJECTSLib)
End Get
End Property

Then, from a page, you can use:

Dim g As Global = DirectCast(Context.ApplicationInstance, Global)
Dim LocalUO As UNIOBJECTSLib = g.UO
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #5
Hi dbui,

I think that the problem is not how you are creating your object, but
rather that you are not checking to see if the object exists in the
application. That is probably why you are getting the "Object instance not
set..." exception.

Dim obj as New MyObject
obj = CType(Application("MyObj"), MyObject)

If(obj IsNot Nothing) Then
....
End If

--
HTH

Kyril

On Mon, 19 Jul 2004 12:33:01 -0700, Tampa .NET Koder
<Ta***********@discussions.microsoft.com> wrote:
Try

Dim obj as New MyObject

obj = Ctype(Application("MyObj") , MyObject)

It is key to use the NEW opeator to create objects in memory, otherwise
you will get this error

"dbui" wrote:
thanks Tam,

I did try that b4 posting the question and it didn't work. It gave me an
error, something like "Object instance was not set..."
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
> "dbui" <nn*****@hotmail.com> wrote in news:#E9iN4bbEHA.3684
> @TK2MSFTNGP09.phx.gbl:
>
> > Application("MyObj") = UO
> >
>
> >
> > How can I retrieve this UO obj from a page?
>
> Dim SomeVariable as MyObj = Application("MyObj")
>
>
>
> --
> Lucas Tam (RE********@rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/



--
--
HTH

Kyril
Nov 18 '05 #6
Thanks John

"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:#A**************@tk2msftngp13.phx.gbl...
"dbui" <nn*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have the following code in global.asax.vb

Public UO As UNIOBJECTSLib()


First, never use public fields.

Private _UO As New UNIOBJECTSLib()
Public Sub New()
MyBase.New()

'This call is required by the Component Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

UO = new UniObjectsLib()


You don't need the above, since I used New in the declaration.
End Sub

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

' Fires when the application is started

Application("MyObj") = _UO

End Sub

How can I retrieve this UO obj from a page?


Public Property UO As UNIOBJECTSLib
Get
Return DirectCast(Application("MyObj"), UNIOBJECTSLib)
End Get
End Property

Then, from a page, you can use:

Dim g As Global = DirectCast(Context.ApplicationInstance, Global)
Dim LocalUO As UNIOBJECTSLib = g.UO
--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Edward Jones | last post: by
4 posts views Thread by Me_Titus | last post: by
1 post views Thread by Fabio Cavassini | last post: by
1 post views Thread by romeo_a_casiple | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.