• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

Session Variable in JavaScript

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");
  • 2
2 Solutions
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.
MikeMCSDAuthor Commented:
I can't do that because the variable is from another page.
Can I do it like this:

var google_conversion_value = <%= Session("TotalSale") %>;
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.
DBAduck - Ben MillerPrincipal ConsultantCommented:
var google_conversion_value = <%= Session("TotalSale") %>; is still a valid construct in ASP.NET so you can do it as you said.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now