Session Variable in JavaScript

Posted on 2006-03-31
Last Modified: 2012-08-13
How do I put a Session variable in JavaScript?

I want to replace "1.0" below with Session("TotalSale")

<script language="JavaScript" type="text/javascript">
  var google_conversion_value = 1.0;

like this:
  var google_conversion_value = Session("TotalSale");
Question by:MikeMCSD
    LVL 6

    Expert Comment

    You would have to do it in server-side script because the javascript is client-side and the two don't communicate. My suggestion would be to put your google_conversion_value into a hidden input field that is set to run at the server. Then you can put it in the sesion varaible.
    LVL 16

    Author Comment

    I can't do that because the variable is from another page.
    Can I do it like this:

    var google_conversion_value = <%= Session("TotalSale") %>;
    LVL 6

    Assisted Solution

    I believe so. I used to do stuff like that with classic ASP, but I haven't really tried with ASP.Net. It should still utilize the Response.Write method and put the variable in.
    LVL 24

    Accepted Solution

    var google_conversion_value = <%= Session("TotalSale") %>; is still a valid construct in ASP.NET so you can do it as you said.


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now