Skip to content
Advertisement

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');

Advertisement

Answer

I guess You can’t. The whole point of local storage is that it is local and You can manipulate it only from javascript. If You need to pass values between server and client You need to use some transport technology – cookies, ajax calls, hidden fields etc. It will all depend on how your application is organized, what kind of information is being stored, its volume, whether you want to redirect or not, but in all cases this should be done using javascript since that’s the only way to access data stored in localStorage.

Advertisement