Results 1 to 6 of 6

Thread: Read Variable from 2nd asp page

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    US, PA
    Posts
    79

    Read Variable from 2nd asp page

    Hi all,

    I have variable declared in my first asp page
    <%
    Dim userId
    userId=Request.form("name")

    I user this userId in my queries and it works fine

    %>

    Now I try to use the userId in my queries, in my second asp page, and it doesn't work. I also used <!--#include file="start.asp"--> in my second asp page.

    Am I doing something wrong in here. Why can my second asp page recognize the variables I declared in my first asp page??

    Reggie

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Variables declared on a page only have scope for that page. You need to use something session variables or another form of persistance.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    You can pass it with a querystring, or if your using a form that is submitted to page 2, you can write the value of UserID into a hidden textfield that will be passed with the form to the next page, then just grab it out of the request.form collection.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Adding a form to EVERY SINGLE PAGE can be a bit, uh...
    TEDIOUS.

    So use session variables!!!

    Code:
    <%
    Function OutSV(Varb)
       Response.Write Session(Varb)
    End Function
    Function ReadSV(Varb)
       ReadSessionVariable = Session(Varb)
    End Function
    Function SetSV(Varb, Val)
       Session(Varb) = Val
    End Function
    %>
    Usage:

    Code:
    <%
    'global.asa
    SetSV "Ab","BA"
    'asp1.asp
    OutSV "Ab" '<---WILL DISPLAY 'BA'
    %>
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Session variables are one solution, but it is at the price of scalabilty. It will work fine as long as the app never needs to grow beyond a single server. A querystring would be a solution that scales to multiple servers if needed.

    I'm not arguing the value of the session object.. I use it on small scale apps that will only be used in an Intranet. But if your planning to do serious development in ASP, don't rely on it too heavily.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  6. #6
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Notice how I said "session variables or another form of persistance."
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

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