Results 1 to 2 of 2

Thread: Has a session variable been created?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Has a session variable been created?

    How do you test if a session variable has been created? I assume it is
    VB Code:
    1. session("alert")=null
    Is this a correct way of doing it?

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Location
    São Paulo, SP, Brasil
    Posts
    118
    I'm not sure of the "right way" for that.

    But I use this:
    VB Code:
    1. <%
    2. If Len(Session("alert")) > 0 Then
    3. Response.Write "alert session does exist"
    4. End If
    5. %>

    And, the right way to check if it's null goes with "IsNull" function:
    VB Code:
    1. If Not IsNull(anyVariable) Then
    2. Response.Write "anyVariable is not null, but it could be empty"
    3. End If

    Anyway, here is the result I got after a few tests:
    Code:
    variable / session               IsNull           IsEmpty           Len = 0
    Not Declared / Created           false            true              true
    = ""                             false            false             true
    = Null                           true             false             true
    = Empty                          false            true              true
    = "anything"                     false            false             false
    That means, if you check for Null, Empty or Len(var) = 0 of a variable right on the first line of the file (before anything else, including declarations, etc), you'll get the results on the first line. And it works for session as well, since they're treated as variables.
    --
    Cauê Cavalheiro Machado Rego

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width