Click here to Skip to main content
15,921,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

I have a value in a javascript variable. I want to save this value in java script session and use this session in c#.

How to set session variable in javascript.



Regrds
Rakesh Tailor
Posted
Updated 18-Sep-19 3:11am

check here: session in javascript in asp.net[^]


--Amit
 
Share this answer
 
Comments
Rakesh Tailor 29-Oct-12 1:38am    
I use this code and an error show below.
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
_Amy 29-Oct-12 1:40am    
Check this link[^].
try this...



var sessionValue = '&lt;%= Session["SesValue"] %&gt;';
alert(" undefind coz no value in session or insilize it on page load in codebehind "+sessionValue);
var valueToset = "hello";
'&lt;%= Session["SesValue"]="'+valueToset+'" %&gt;';

sessionValue = '&lt;%= Session["SesValue"] %&gt;';

alert(sessionValue);
 
Share this answer
 
Comments
Rakesh Tailor 29-Oct-12 6:53am    
I used this but an error showing.
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
NAPorwal(8015059) 29-Oct-12 7:22am    
can you show here your code as such u have written. cause its working fine in my page.
vishnu gh 18-Sep-19 9:11am    
This is Correct But How to Pass this variable to
C#

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