We help IT Professionals succeed at work.

Session Variable in JavaScript

MikeMCSD
MikeMCSD asked
on
Medium Priority
672 Views
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;
//-->
</script>

like this:
  var google_conversion_value = Session("TotalSale");
Comment
Watch Question

Commented:
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.

Author

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") %>;
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
SQL Server Architect
CERTIFIED EXPERT
Commented:
var google_conversion_value = <%= Session("TotalSale") %>; is still a valid construct in ASP.NET so you can do it as you said.

Ben.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.