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.

Passing clientside value to server side

Discussion in 'C#' started by shajimanjeri, Jun 4, 2007.

  1. #1
    Good morning all,
    Hi,

    I have a doubt. How can I pass a javascript value to a asp varible.
    Let me tell in brief,
    <script>
    var x = 2
    </script>
    now I need to pass this variable value to a asp variable
    <%
    dim y
    y = [Here I need to bring that javascript variable value]
    %>

    Thanks in advance

    With regards
    Shaji
     
    shajimanjeri, Jun 4, 2007 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You would need to have the client side script assign the value to a form element or control (depending on if you are talking classic or .Net asp) like a hidden form input.
     
    AstarothSolutions, Jun 4, 2007 IP
  3. shajimanjeri

    shajimanjeri Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,
    Thanks for your reply..

    Could you give me more explanation with just an example please?

    with regards
    Shaji
     
    shajimanjeri, Jun 4, 2007 IP
  4. slawek

    slawek Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can send data with hidden fields.

    <INPUT id="myfield" type="hidden" value="something" runat="server">
     
    slawek, Jun 4, 2007 IP
  5. shajimanjeri

    shajimanjeri Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    But I am using classic asp. In classic asp how to do?

    regards
    Shaji
     
    shajimanjeri, Jun 5, 2007 IP
  6. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #6
    Dude try the easiest way.

    Get the data on client side, save it to a cookie then retrieve it via ASP

    I use that type of things on www.mobile.am you might wanna look at the JavaScripts, later I retrieve the data in the cookie via ASP and show the site the way I need to :)
     
    ludwig, Jun 5, 2007 IP
  7. slawek

    slawek Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
  8. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #8
    A lot depends on what the javascript that originally generates the value is doing. If it is simply a calculation on another input field then simply regenerate the value when the page is submitted, if this is not possible then an onclick or such script can be added to set the value of the calculated field to a hiddenfield on the form.
     
    AstarothSolutions, Jun 8, 2007 IP
  9. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #9
    you could have javascript redirect to the same url but with a url querystring, then have ASP read the querystring variable that javascript redirected with.
     
    ccoonen, Jun 8, 2007 IP
  10. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #10
    I was thinking the same :D

     
    surfnearnzone, Jun 10, 2007 IP
  11. kashif.nazar

    kashif.nazar Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    you can do it in two ways
    1. If you want to pass the value from the script to other page, then put the value in the query string and get from other page.
    like this
    <script>
    var x = 2
    form.Post(index.asp?val=)
    </script>

    <%
    dim y
    y = Request.QueryString(val)
    %>

    you can get the value by this,

    2.. The second method is ... put the value in a hidden control.
    like form.HidControl.value = 2;

    and get the value from that control...
     
    kashif.nazar, Jun 10, 2007 IP