Introduction: Asp.Net Get Session Values in JavaScript

In this post, we will learn about getting ASP.NET session value in javascript.

Description:

In my previous posts I have explained various topics like Introduction To JSON, Ajax Control in ASP.NET, AJAX Basics, Optional Arguments In C#, difference between Stack and Heap memory in C#, Difference Between Class And Structure, ASP.NET Core, C# static constructor.

Now in this post, I will explain about Asp.Net Get Session Values in JavaScript.

By making use of “Session” property we can easily access session variable value in JavaScript or jQuery.

Now create  Web form application in Visual Studio and write below lines of code in it.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Session Values in JavaScript</title>
   <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
</head>
<body>
    
<form id="frmMain" runat="server">
        <label id="lblEmployeeName" />
    </form>

</body>
</html>

Now, Write below lines of code in codebehind file of above .aspx

protected void Page_Load(object sender, EventArgs e)
{
            Session["EmployeeName"] = "Raj Mehta";
}



Summary

I hope you got an idea about Asp.Net Get Session Values in JavaScript.
I would like to have feedback from my blog readers.
Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website