Avoiding late binding

A

Andrew Morton

(First posted to microsoft.public.dotnet.general by mistake.)

I don't know the correct terminology, but I'm sure there's a better way to
do the following with .aspx pages:-

In global.asax, I create an instance of an entity (basketCentral.vb) which
has subroutines, functions and variables which I want to access from any
page:-

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim basket As NS.basketCentral = New NS.basketCentral
Session("basket") = basket
End Sub

Then to use a public function in it, I use, for example,

userID=Session("basket").logon(username, passwd)

or for a public subroutine,

Session("basket").addToBasket(shopitem)

It works, but is this the "correct" way of doing it? VS.NET prompts with
GetType as soon as I've typed the dot after Session("basket"), which leads
me to think I'm missing something and causing it to use late binding.

Andrew
 
H

Herfried K. Wagner [MVP]

Andrew Morton said:
In global.asax, I create an instance of an entity (basketCentral.vb) which
has subroutines, functions and variables which I want to access from any
page:-

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim basket As NS.basketCentral = New NS.basketCentral
Session("basket") = basket
End Sub

Then to use a public function in it, I use, for example,

userID=Session("basket").logon(username, passwd)

or for a public subroutine,

Session("basket").addToBasket(shopitem)

If you want to use 'Option Strict On', you will have to do a type cast:

\\\
DirectCast(Session("basket"), BasketCentral).AddToBasket(...)
///
 
A

Andrew Morton

Herfried said:
If you want to use 'Option Strict On', you will have to do a type
cast:
\\\
DirectCast(Session("basket"), BasketCentral).AddToBasket(...)
///

Aha! Now it is clear. Thank you.

Andrew
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top