Mehmet Ince Mehmet Ince - 2 months ago 16
Javascript Question

How to access Session variables and set them in javascript?

In code-behind I set

with some data.

Session["usedData"] = "sample data";

And the question is how can I get the Session value(in my example; "sample data") in javascript and set
with a new value?


Accessing & Assigning the Session Variable using Javascript:

Assigning the ASP.NET Session Variable using Javascript:

 <script type="text/javascript">
function SetUserName()
    var userName = "Shekhar Shete";
    '<%Session["UserName"] = "' + userName + '"; %>';
     alert('<%=Session["UserName"] %>');

Accessing ASP.NET Session variable using Javascript:

<script type="text/javascript">
    function GetUserName()

        var username = '<%= Session["UserName"] %>';
        alert(username );