I'm wondering if it's possible to set a Session Variable in Javascript. I've been researching it and am finding mixed answers. Is there a way to do this and be able to reference that value in the code-behind?
Thanks,
Printable View
I'm wondering if it's possible to set a Session Variable in Javascript. I've been researching it and am finding mixed answers. Is there a way to do this and be able to reference that value in the code-behind?
Thanks,
There is no direct way of setting a session variable using javascript. Sessions are maintained on the serever and js runs client side. You could probably use ajax to call server code to set a session variable or maybe you could just use a cookie.
Thanks Mark, I appreciate your response!
HTML5 has introduced Local Storage. If you need support in older browsers (< IE8), check for availability with Modernizr and use a polyfill if required.
http://www.w3.org/TR/webstorage/
http://dev.opera.com/articles/view/web-storage/
https://developer.mozilla.org/en-US/docs/DOM/Storage
The alternative would be to use Cookies as MarkT suggested, but they come with the overhead of being sent with every request/response and are transmitted in plaintext unless they are specifically set to send over SSL.