Click here to Skip to main content
15,918,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to assign a value to session using Javascript. I tried to do google but it gives me error for <% %> syntax.

Please Help its very very Urgent.

Thanks,
Chirag.
Posted
Comments
Sanket Saxena 17-Oct-12 7:35am    
What u have tried give sample
Chirag Shah.Gogari 17-Oct-12 7:54am    
Hi Sanket This is below example -
<%Session["Test"] = "Welcome Mamu";%>

you can call codebehind function from javascript and pass the value as parameter and then assign to session variable.

Calling a code-behind function from JavaScript[^]
 
Share this answer
 
Comments
Chirag Shah.Gogari 17-Oct-12 7:55am    
Hi Manak, This examples assigns value to a variable. But I want to assign it to a session variable in this Java Script.
manak chand 17-Oct-12 7:59am    
you will be having value in javascript, then pass it to code behind function and assign the javascript value to session in code behind function.
The Requirement got changed. Thanks to All...
 
Share this answer
 
Try like this.....


XML
<%
  Session("MyTest") = Now() ' store date and time in session var
%>
<script type="text/javascript">
  var whatTimeIsIt = '<%=Session("MyTest")%>';
  alert(whatTimeIsIt);
</script>
 
Share this answer
 
Comments
Chirag Shah.Gogari 17-Oct-12 8:02am    
Hi,

This solution is as per VB.Net format I convert it into C# and I got same error as below -

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

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