Question on using Session variable

Results 1 to 2 of 2

Thread: Question on using Session variable

  1. #1
    Join Date
    Dec 1969

    Default Question on using Session variable

    Hi, I&#039;m sorry if this question has been asked before. If anyone knows where this question has been answered, please send me the link. Thnaks!<BR><BR>I&#039;ve just started learning about using Session variables. My problem is this:<BR><BR>To create a new Session variable name Variable1 for example, this is what we do:-<BR>Session("Variable1") = "String"<BR><BR>What I want to do is to pass in the variable name as a variable, as in like this:<BR>VarName = "Variable1"<BR>Session(VarName) = "String"<BR><BR>However when I retrieved Session("Variable1") in another script which is in the same session, the code return an empty string. This was the code snippet I used to retrieve the Session variable:<BR><BR>VarName = "Variable1"<BR>VarValue = Session(VarName)<BR> <BR><BR>Why I need to do this is because I stored the variable names that I want to store as Session variables in an array, so that I can conveniently use a loop to create these variables.<BR><BR>Can I check if there is a better a way to do this, or if not, what is wrong with my code snippet above. Have I left out something or what?<BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Should have worked...

    I&#039;d guess there is some other problem.<BR><BR>Try this in the *SECOND* page, where you are trying to retrieve the value:<BR><BR>&#060;%<BR>For Each sname In Session.Contents<BR> Response.Write sname & ": " & Session(sname) & "&#060;br/&#062;"<BR>Next<BR>%&#062;<BR><BR>That will show you *all* the session variables currently available. If you don&#039;t get any, then you have a completely different problem.<BR><BR>If the spellings of the names aren&#039;t what you expected, then go debug your code.<BR><BR>

Posting Permissions

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