1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with ASP and onClick

Discussion in 'C#' started by rjhilliard, May 18, 2006.

  1. #1
    Hi, this is my first post so please forgive me if I make a protocol gaffe.

    I am trying to populate and pass a session variable from one page to another using asp and the javascript onClick event handler.
    Here is my code:

    Response.Write "<a href = 'dr_ship_detail_mtd.asp' onClick=""" & session("ProdCode") = "PLT""" & ">" & FormatCurrency(round(dblMTDShipValue(iIndex),0),0,-2,-2,-2) & "</a>"

    What happens is that when I execute the original page instead of displaying a numeric value as a link. I see False in it's place. I need to populate this session variable prior to executing the link to the next web page. Is what I am trying to do possible? Could someone help me out with this, please?
     
    rjhilliard, May 18, 2006 IP
  2. ServerUnion

    ServerUnion Peon

    Messages:
    3,611
    Likes Received:
    296
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what are you doing with the onclick? I dont see a client side directive to execute.

    You may want to look into "return false" on your javascript. I have some popup scripts that would leave me on a page with only false printed on it unless I returned false to the onclick event.

    Good luck.
     
    ServerUnion, May 18, 2006 IP
  3. jfilley

    jfilley Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you are trying to populate the session variable with the onClick client side javascript event, that won't work. Why dont you just populate the session variable in your asp script in seperate code piece. It doesn't hurt to just populate it even if they don't click the button

    session("ProdCode") = "PLT"

    then do your response.write link
     
    jfilley, May 19, 2006 IP
  4. rjhilliard

    rjhilliard Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have come to realize that using the javascript event handler will not work.
    I have seen code that seems to work when you insert the language="Vbscript" statement. I am in classic ASP using vbscript as my language of choice.
    So i have decided to try that and send the code off to a subroutine when the user clicks the link. See code below:

    Response.Write "<a href = 'dr_ship_detail_mtd.asp' language=""VBScript"" OnClick=""PopSessVar()"">" & FormatCurrency(round(dblMTDShipValue(iIndex),0),0,-2,-2,-2) & "</a>"

    Then in the <head> section I create the subroutine within the <script> tags
    <script language="vbscript">
    sub PopSessVar()
    session("ProdCode") = 'PLT'
    end sub
    However when the link transfers control to the new page the session variable does not contain PLT. I know that the subroutine is being entered however because I set up msgbox to test whether the code was branching there.
    Is there any reason why the session var would not populate?
     
    rjhilliard, May 19, 2006 IP
  5. ServerUnion

    ServerUnion Peon

    Messages:
    3,611
    Likes Received:
    296
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Session variables are set server side, not client side. Doesn't matter if you use JS or VB it wont work.

    Since you are already doing a postback to the server, set the session at that time and response.write the URL with the updated querystring as jfilley stated above.


    You link on the page would be :

    dr_ship_detail_mtd.asp?ProdCode=PLT

    on that page place the script

    session("ProdCode")=request.querystring("ProdCode")
     
    ServerUnion, May 19, 2006 IP
  6. rjhilliard

    rjhilliard Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you that's exactly what I was looking for!
    I knew there was a way to get what I wanted done I just couldn't seem to put 2 & 2 together and come up with 4.
    Thanks again.
     
    rjhilliard, May 22, 2006 IP