Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
how to set session values using javascript.
Posted 18-May-11 1:45am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 .
  Permalink  
Comments
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Modern browsers support client-side session storage for Javascript: sessionStorage[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 445
1 CHill60 410
2 Sergey Alexandrovich Kryukov 354
3 BillWoodruff 190
4 PIEBALDconsult 160


Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 18 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100