Saturday, 22 April 2017

Get (Access) Session Values in JavaScript (Client Side) in asp.net

Get (Access) Session Values in JavaScript (Client Side) in asp.net

Description:


In this example we explain that how to access session value at client side JavaScript in asp.net or how to get session variable value in JavaScript at client side in asp.net.or how to access asp.net session value at client side using JavaScript or JQuery.

Sometime we have requirement like to display login user details at client side or in some functionality if we have to check the session is exists for the current user or not at that time below code is very useful.

Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Asp.Net Access Session Variable Value in JavaScript or jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
var name = 'Welcome '+' <%= Session["UserName"] %>'
$('#lbltxt').text(name)
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label id="lbltxt" />
</div>
</form>
</body>
</html>


0 comments:

Post a Comment