Showing posts with label ihave. Show all posts
Showing posts with label ihave. Show all posts

Thursday, March 29, 2012

Session Variable

If I have a Session variable such as Session("Id") which is a long, do I
have to convert it before assigning it to a long variable?
Dim nId As Long
nId = Session("Id")On 7/20/2004 10:01 PM, William Gower wrote:

> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")
>
Only if you have Option Explicit on (which I highly recommend; see the
Properties of your project)...otherwise at runtime it will convert it
and if it's invalid, you'll get a format exception...
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7/20/2004 10:59 PM, Craig Deelsnyder wrote:

> On 7/20/2004 10:01 PM, William Gower wrote:
>
> Only if you have Option Explicit on (which I highly recommend; see the
> Properties of your project)...otherwise at runtime it will convert it
> and if it's invalid, you'll get a format exception...
>
sorry, I meant Option Strict...
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Yes, at least if you have Option Strict on (which you should). If you
know in advance that the Session variable holds a Long (and never
anything else), you can use DirectCast to maximize performance:
Dim nId As Long
If Session("Id") Is Nothing Then
' Session has expired, or session variable was never set.
Else
nId = DirectCast(Session("Id"), Long)
End If
"William Gower" <w_gower@.hotmail.com> wrote in message news:<uh43d6sbEHA.2408@.tk2msftngp13.
phx.gbl>...
> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")

Session Variable

If I have a Session variable such as Session("Id") which is a long, do I
have to convert it before assigning it to a long variable?

Dim nId As Long
nId = Session("Id")On 7/20/2004 10:01 PM, William Gower wrote:

> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")

Only if you have Option Explicit on (which I highly recommend; see the
Properties of your project)...otherwise at runtime it will convert it
and if it's invalid, you'll get a format exception...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7/20/2004 10:59 PM, Craig Deelsnyder wrote:

> On 7/20/2004 10:01 PM, William Gower wrote:
>> If I have a Session variable such as Session("Id") which is a long, do I
>> have to convert it before assigning it to a long variable?
>>
>> Dim nId As Long
>> nId = Session("Id")
>>
>>
> Only if you have Option Explicit on (which I highly recommend; see the
> Properties of your project)...otherwise at runtime it will convert it
> and if it's invalid, you'll get a format exception...
sorry, I meant Option Strict...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Yes, at least if you have Option Strict on (which you should). If you
know in advance that the Session variable holds a Long (and never
anything else), you can use DirectCast to maximize performance:

Dim nId As Long
If Session("Id") Is Nothing Then
' Session has expired, or session variable was never set.
Else
nId = DirectCast(Session("Id"), Long)
End If

"William Gower" <w_gower@.hotmail.com> wrote in message news:<uh43d6sbEHA.2408@.tk2msftngp13.phx.gbl>...
> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")

Saturday, March 24, 2012

Session variables

Hello!

I'm very new with ASP.NET so my question may be...

I'mworking in a webshop and I'm trying to build a shopping cart. Ihave made the products page with a datalist and a Access DB. My problemis when passing the item I chose to buy to the cart. I'm trying to usea session variable but don't know how send (cart.aspx?id=xx) and toreceive it.

Could someone try to explain that to me? Some examples would help too. (working with .NET 1.1 and VB).

Thanks in advance.

Store your id in a Session variable..

Session("ID") = some_value..

In your cart.aspx you can use

id = Cint(Session("ID"))

Don't forget to check if Session("ID") is Not Nothing in cart.aspx, otherwise it throws exceptions.


You can also take a look at this article to learn more about ASP.NET state management:

http://msdn2.microsoft.com/en-us/library/z1hkazw7.aspx