set a session variable in javascript code example
Example 1: how to set session storage in javascript
sessionStorage.setItem('key', 'value');
let data = sessionStorage.getItem('key');
sessionStorage.removeItem('key');
sessionStorage.clear();
Example 2: set a value in session using javascript
<script type="text/javascript">
function GetUserName()
{
var username = '<%= Session["UserName"] %>';
alert(username );
}
</script>
Example 3: set a value in session using javascript
<script type="text/javascript">
function SetUserName()
{
var userName = "Shahid Bhat";
'<%Session["UserName"] = "' + userName + '"; %>';
alert('<%=Session["UserName"] %>');
}
</script>