aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.Net Get (Access) Session Values in JavaScript (Client Side)

Feb 27, 2017

Here we will learn how to access session variable in JavaScript with example or access session value in jQuery with example or access session values in client side using JavaScript with example or get session variables in JavaScript with example or get session variable values in client side in c#, with example. By using “Session” property we can easily access session variable value in JavaScript or jQuery based on our requirements.


By using Session property we can easily access session values in JavaScript or jQuery based on our requirements. Following is the simple code snippet to get session values in values in JavaScript or jQuery.

JavaScript or jQuery Code

<script type="text/javascript">
$(function() {
var name = 'Welcome '+' <%=Session["UserName"] %>'

If you want complete example to access session values in JavaScript or jQuery open your aspx page and write the code like as shown following.


<html xmlns="">
<title>Asp.Net Access Session Variable Value in JavaScript or jQuery</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(function() {
var name = 'Welcome '+' <%= Session["UserName"] %>'
<form id="form1" runat="server">
<label id="lbltxt" />

If you observe above code we are trying to get “UserName” session value in our client side using Session property.

Now open code behind file and write the code like as shown following

C# Code

using System;

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
Session["UserName"] = "Guest";


Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Session("UserName") = "Guest"
End Sub
End Class


When we run above code we will get result like as shown below

Access Asp.Net Session Variable Values in Client Side using JavaScript or jQuery

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Shivam said...

good :)

vijay t said...
This comment has been removed by the author.
vijay t said...


geetha sridhar said...

Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
Best AWS Training in Chennai | Amazon Web Services Training Institute in Chennai Velachery, Tambaram, OMR
Advanced AWS Training in Bangalore |Best AWS Training Institute in Bangalore BTMLA ,Marathahalli

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.