You must Sign In to post a response.
  • Category: ASP.NET

    How get javascript session values in code behind into asp.net

    Hi,

    I am trying following javascript coding. Now I wan this session
    value in cs. How do it.

    <script type="text/javascript">
    function SetUserName()
    {
    var userName = "Shekhar Shete";
    '<%Session["UserName"] = "' + userName + '"; %>';
    }
    </script>
  • #765627
    First check if session value is properly stored in javascript, see below snippet

    //set a session
    <script type="text/javascript">
    function SetUserName()
    {
    var userName = "test";
    '<%Session["UserName"] = "' + userName + '"; %>';
    alert('<%=Session["UserName"] %>');
    }
    </script>

    //get it in code behind
    string szName = 'Session["UserName"]'.toString();

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments