0

I followed the answer here by defining the js variable ahead. However the scope of that variable doesn't stay if I go to another page when browsing. Which seems reasonable since I do go to another page in the browser. So I wonder how can I save the js variable across multiple pages when I'm browsing? Do I need to use session variables, querystring in C#? Or is there any better solution?

Community
  • 1
  • 1
starcorn
  • 8,261
  • 23
  • 83
  • 124
  • You could try using a cookie to pass down the value. (not everyone has cookies enabled though) Else the only way i can think of are sessions. – Mark Verkiel Jul 18 '12 at 14:37
  • You could use [web storage](http://www.w3.org/TR/webstorage/) (either local- or sessionStorage) to save the variable. – Andreas Jul 18 '12 at 14:42

2 Answers2

0

There are no variables with a scope across pages. On the client side you can use cookies or querystrings, or you can keep the value in a session variable on the server side, or send it in post data to the server side, and put it in the page so that it is available in the client side code.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

One way would be use local storage, a HTML5 feature.

http://paperkilledrock.com/2010/05/html5-localstorage-part-one/

Of course, it depends on your clients and whether you expect them to be able to use HTML5.

Otherwise Cookies are probably the best route.

KingCronus
  • 4,509
  • 1
  • 24
  • 49