• 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;
//-->
</script>

like this:
  var google_conversion_value = Session("TotalSale");
0
MikeMCSD
Asked:
MikeMCSD
  • 2
2 Solutions
 
fizchCommented:
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.
0
 
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") %>;
0
 
fizchCommented:
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.
0
 
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.

Ben.
0

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