Session Variables

Results 1 to 4 of 4

Thread: Session Variables

  1. #1
    Kevin Guest

    Default Session Variables

    When I set session variables using this format:<BR><BR>&#060;%@ Language=VBScript &#037;&#062;<BR><BR>&#060;% session("sort") = "Date" &#037;&#062; <BR><BR>I can set the variables with no problem. However I cannot execute any Button_OnClick() subs. When I use VBScript like this :<BR><BR>&#060;SCRIPT LANGUAGE="VBScript"><BR>&#060;!--<BR> sub set_session()<BR> session("sort")="Date"<BR> end sub<BR>--><BR><BR>THe subroutine executes but the session variable gives me a type mismatch error on the variable declaration. I&#039m using IE5 and IIS and Active Server Pages. PLease help!<BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Session Variables

    One thing you&#039ve got to remember is that ASP is a server-side scripting language. When you write an ASP file, everything between &#060;% and &#037;&#062; is parsed BEFORE the browser sees any code. So, that&#039s why if you view an asp page in your browser and go to View Source, you don&#039t see any ASP tags, ASP variables, etc.<BR><BR>That being said, hopefully it makes, now, a bit of sense why you can&#039t alter a session variable (which is an asp variable, server-side) in a client-side script. Client-side scripts cannot modify Server-side information. It&#039s just impossible. You&#039d have to call a new page, reload the page, do something, but that something would have to reconnect to the server if you want modification of server-side variables AFTER you&#039ve passed control to the client (browser).<BR><BR>Hope this helps!

  3. #3
    Kevin Guest

    Default RE: Session Variables

    That helped a bunch. I was able to populate session variables within a client side script by doing this:<BR>&#060;SCRIPT language=VBScript><BR> <BR> sub rbdate_OnCLick()<BR> <BR> &#060;%session("sortby")="Date"&#037;&#062;<BR> msgbox session("sortby")<BR> end sub<BR> <BR>&#060;/SCRIPT><BR><BR>But I can&#039t seem to figure out how to populate the session variable with the contents of another variable. aghhhhh

  4. #4
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Session Variables

    &#060;%<BR>Dim str = "Hello, world!"<BR><BR>Session("SortBy") = str<BR>&#037;&#062;<BR><BR>Keep in mind the difference between server-side variables and client-side variables. I sense that you are wanting to set the session variable equal to a client-side variable. You cannot do this!<BR><BR>If you are needing to pass information from one page to another (which is sounds like you are trying to do with session variables), I&#039d recommend you use another approach. Hopefully you&#039ll find Joao&#039s article useful, "Four Ways to Pass Data in ASP"<BR><BR>http://4guysfromrolla.com/webtech/041399-1.shtml<BR><BR>Happy Programming!


Posting Permissions

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