Question

I want to get session in jQuery(v 1.9.1).

I used the following code:

<script>
    var testUser = '<%= Session["User"] %>';
    alert(testUser);
</script>

But I get the following error:

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

"Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)"

Était-ce utile?

La solution

Try this

<script type="text/javascript">
    function getsession(){    
        var name = "<%= Session["test"]%>";
        alert('Session value = >' + name );
    };
</script>

OR you can try this

  // To Read
  $(function() {
  //Set the value to session
  $.session.set("userName", $("#uname").val());
  //Get the value to session
  alert($.session.get("myVar"));
  });
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top