ZSH
ZSH

Reputation: 661

Get session issue

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. <% ... %>)"

Upvotes: 1

Views: 3344

Answers (1)

AB Vyas
AB Vyas

Reputation: 2389

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"));
  });

Upvotes: 1

Related Questions