Session isNothing

Discussion in 'C#' started by PartyRama.co.uk, Aug 20, 2009.

  1. #1
    Hi

    I have a problem with some of my session variables

    Can you please tell me what is the best way to know if the session has any value in it or it is empty?

    I cannot find something like

    If IsNothing(Session("myVar")) then
    ...
    End if


    Please help
    Sri
     
    PartyRama.co.uk, Aug 20, 2009 IP
  2. web-bod

    web-bod Guest

    Messages:
    17
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    depends what you store in it, they're not strongly typed. So for strings initialise to "" for numerics "-1" or something like that
     
    web-bod, Aug 20, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    
    If Session("myvar") Is Nothing Then
    ...........
    End If
    
    Code (markup):
    or...
    
    If Session("myvar") IsNot Nothing Then
    .............
    End If
    
    Code (markup):
     
    camjohnson95, Aug 20, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    oh, that's with asp.net ... unsure of if it works with classic. but with asp classic you should just be able to do:
    If Session("myvar") <> "" Then ...
     
    Last edited: Aug 20, 2009
    camjohnson95, Aug 20, 2009 IP