In code-behind I set Session
with some data.
Session["usedData"] = "sample data";
And the question is how can I get the Session value(in my example; "sample data") in javascript and set Session["usedData"]
with a new value?
In code-behind I set Session
with some data.
Session["usedData"] = "sample data";
And the question is how can I get the Session value(in my example; "sample data") in javascript and set Session["usedData"]
with a new value?
I was able to solve a similar problem with simple URL parameters and auto refresh.
You can get the values from the URL parameters, do whatever you want with them and simply refresh the page.
HTML:
C#:
first create a method in code behind to set session:
then call it from client side:
you should set EnablePageMethods to true:
Accessing & Assigning the Session Variable using Javascript:
Assigning the ASP.NET Session Variable using Javascript:
Accessing ASP.NET Session variable using Javascript:
If you want read Session value in javascript.This code help for you.
<script type='text/javascript'> var userID='@Session["userID"]'; </script>
I was looking for solution to this problem, until i found a very simple solution for accessing the session variables, assuming you use a .php file on server side. Hope it answers part of the question :
access session value
Edit : better example below, which you can try on phpfiddle.org, at the "codespace" tab
set session value
pass it a variable of whatever, you may want to. eg,
This should work, tho' not tested it.
Assuming you mean "client side JavaScript" - then you can't, at least not directly.
The session data is stored on the server, so client side code can't see it without communicating with the server.
To access it you must make an HTTP request and have a server side program modify / read & return the data.