Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to set session values using javascript.
Posted

You can not assign value to session variable from java script.
The reason is very clear session is store on server .So to assign session value you need post back .

However you can assign value of session variable to java script variable.

You have to use server-side programming (vb.net or C# or ...). Maybe is better you use a button in asp.net .
 
Share this answer
 
Comments
you can't assign value to session variable through javascript. Because its a server side code. you will get the session variable through javascript.
var color="<%=Session["Color"]%>";
have a look there[^] having same question with some suggested solutions.
 
Share this answer
 
Modern browsers support client-side session storage for Javascript: sessionStorage[^]
 
Share this answer
 
how to set session values using javascript.
Well, as others have already stated that Session is a server side thing and Javascript is a client side thing.

Though, if you want to set a session via Javascript, you can do it using XMLHttpRequest.
Read about it here:XMLHttpRequest[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900