ASP Request.QueryString Question

Discussion in 'C#' started by tdd1984, Oct 4, 2008.

  1. #1
    I'm just curious is this right below?

    <%
    Dim variable
    variable = Request.QueryString("channel")
    %>

    we need to grab the text from www.mydomain.com?channel=text

    Then pass it into a URL on the page? So basically just grab the url parameter "channel" then pass it into another URL on the page..

    how would I do that? Is the top code right?
     
    tdd1984, Oct 4, 2008 IP
  2. fulltilt

    fulltilt Peon

    Messages:
    128
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    fulltilt, Oct 4, 2008 IP
  3. tdd1984

    tdd1984 Well-Known Member

    Messages:
    2,357
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    150
    #3
    It won't be entering into a database, but you say this is correct below?

    <%
    Dim source
    source = Request.QueryString("source")
    %>


    So the parameter gets signed into source? Then I can use the response.write() function to show it in the url?
     
    tdd1984, Oct 4, 2008 IP
  4. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Your code is correct. I added the line to write the url:

    <%
    Dim source
    source = Request.QueryString("source")

    Response.Write("<a href=""somepage.asp?source=" & source & """>click here</a>")
    %>


    Note that you have to use double quotes where you need a quotation mark in your response.write string.

    -Jim
     
    jgarrison, Oct 5, 2008 IP
  5. tdd1984

    tdd1984 Well-Known Member

    Messages:
    2,357
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    150
    #5
    k..

    Can't I just do it like this
    <a href="page.php?source=<% Response.Write("source") %>">
     
    tdd1984, Oct 5, 2008 IP
  6. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes, you can. But remove the quotes or you'll pass the literal text string source on the querystring instead of the variable.
    You can also do this:
    <a href="page.php?source=<%=source %>">

    %= is a shorthand way of writing response.write
    -Jim
     
    jgarrison, Oct 5, 2008 IP
  7. tdd1984

    tdd1984 Well-Known Member

    Messages:
    2,357
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    150
    #7
    I need to use response.write() to echo the variable out though don't I?

    What does =source mean?

    I need the text from the variable to into into the URL query string.
     
    tdd1984, Oct 5, 2008 IP
  8. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Sorry for the confusion. I renamed your variable to source in my example. I should of written:

    <%
    Dim variable
    variable = Request.QueryString("channel")
    %>

    And then you echo the variable out using:

    <a href="page.php?source=<%=variable %>">

    <%=variable %> is a shorthand way of writing <% Response.Write(variable) %>

    Hope that clears up everything.
    -Jim
     
    jgarrison, Oct 6, 2008 IP