Frage

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

War es hilfreich?

Lösung

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"));
  });
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top