Click here to Skip to main content
11,634,815 members (64,497 online)
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 8,736
1 Sergey Alexandrovich Kryukov 8,419
2 Mika Wendelius 6,845
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,205


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 18 May 2011
Copyright © CodeProject, 1999-2015
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