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);
2
  • possible duplicate of Assign session value using javascript Commented Apr 3, 2014 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 Commented Apr 3, 2014 at 11:59

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.