Link to home
Start Free TrialLog in
Avatar of Pralad
PraladFlag for India

asked on

How to set session variable in Javascript

Hi,

I wish to assign session variable from javascript. I am able to do by means of below code
'<%Session["Key"] = "' + Key + '"; %>';
at aspx page value assigned to Session["Key"] is the variable value "Key"

but when trying to access from .aspx.cs (code behind) getting session["key"] values are  ' + Key + '. and looking to retrieve actual value of variable Key instead of " ' + Key + ' ", how could this be achieved.

Please suggest.

Thanks


Avatar of leakim971
leakim971
Flag of Guadeloupe image

ASKER CERTIFIED SOLUTION
Avatar of dxdinh
dxdinh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pralad

ASKER

Thanks Leakim971.

But, I am looking for assigning value to session variable through javascript. All the above examples are related to retrieval. Please provide method to assing vlaue to session variable in JS without Webservice,etc.

The session variable of the server of something similar on the browser
I can not stress this enough - you can not set session variable using client side javascript. You have to pass to the server by the mean of using query string or hidden field post back.

Perhaps, you can tell us what you want to achieve then we can help you to achieve the same result without setting the session variable through client side javascript (it's just not possible).

>The session variable or the server or something similar on the browser ?

Using PageMethods  (check the Page_Loads section) : http://aspalliance.com/1922_PageMethods_In_ASPNET_AJAX.2
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
You can not set session via client script - it's against security - if everyone can set session variable via javascript on client side - they can easily take down your server.