How do you test if a session variable has been created? I assume it isIs this a correct way of doing it?VB Code:
session("alert")=null
Printable View
How do you test if a session variable has been created? I assume it isIs this a correct way of doing it?VB Code:
session("alert")=null
I'm not sure of the "right way" for that.
But I use this:
VB Code:
<% If Len(Session("alert")) > 0 Then Response.Write "alert session does exist" End If %>
And, the right way to check if it's null goes with "IsNull" function:
VB Code:
If Not IsNull(anyVariable) Then Response.Write "anyVariable is not null, but it could be empty" End If
Anyway, here is the result I got after a few tests:
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.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