Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set localStorage or Session variable in asp.net page and read it in javascript on the other page?

As in question. Is it possible to set variable in asp.net page in localStorage and retrieve it on the other page?

How to set localStorage variable in asp.net. Is it possible? After that I could read variable using:

localStorage.getItem('UserID');
like image 280
mashet Avatar asked Oct 24 '13 09:10

mashet


People also ask

What is the difference between session and local storage for JavaScript?

Since we can set up javascript code in asp.net and insert into the client side, there's no difference with the session or local storage. That will set the session (you could do local) storage variable to the value 12345.

Is it possible to set session variable in another page?

I think setting session variable in page & read variable in javascript of another page is possible. But, if you are looking out for localstorage that won't be. It needs javascript. For session variable e.g.

Can local storage be used with ASP NET?

Local storage isn't ASP.NET, it's a web browser API. You use javascript to work with it. As to your Session question, you can always make a request to the server to get any value you might generally want, if you've built something to answer those requests.

What are web storage objects localStorage and sessionStorage?

Web storage objects localStorage and sessionStorage allow to save key/value pairs in the browser. What’s interesting about them is that the data survives a page refresh (for sessionStorage) and even a full browser restart (for localStorage ).


1 Answers

I think setting session variable in page & read variable in javascript of another page is possible. But, if you are looking out for localstorage that won't be. It needs javascript. For session variable e.g.
A.aspx

<% Session["username"]="Donald Duck"; %>

B.aspx

>  <script type="text/javascript">
>       var user = "<%= Session["username"] %>";
>       document.write(user);
>  </script>
like image 186
Vishwajeet Kulkarni Avatar answered Nov 12 '22 05:11

Vishwajeet Kulkarni