0

I am using the below code to assign the session value. But it's working with default value, while i assign the javascript variable means i got error.

  //Working 
  <%Session["UserSession"] = "hai"; %>
  var session_value='<%=Session["UserSession"]%>';
  alert(session_value);


 //Not Working 
  var value ="hai";
  <%Session["UserSession"] = value ; %>
  var session_value='<%=Session["UserSession"]%>';
  alert(session_value);
user3085540
  • 275
  • 3
  • 12
  • 27
  • possible duplicate of [Assign session value using javascript](http://stackoverflow.com/questions/17720916/assign-session-value-using-javascript) – Satpal Apr 03 '14 at 11:59
  • You do not appear to have a good understanding of the ASP.NET page life-cycle. You are mixing server-side and client-side script – freefaller Apr 03 '14 at 11:59

1 Answers1

0

We cannot assign the server-side session variable from the client script.

Instead, you can make an Jquery AJAX request and call the webmethod, which in turn sets the session variable in the code behind. You can pass the value into the webmethod.

Karan
  • 3,265
  • 9
  • 54
  • 82