Aspdotnet-Suresh

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

jQuery Get Access Session Variable Value in Asp.net

Jun 23, 2013
Introduction

Here I will explain simple jQuery code to get / access asp.net session variable value in jQuery or how to access or get session variable value using jQuery in asp.net.

Description:

In previous articles I explained jQuery slideup, slidedown and toggle effects example, jQuery Draggable & Resizable div with example, jQuery split the string jQuery Scrollable gridview with fixed header and many articles relating to JQuery, JavaScript, asp.net, code snippets. Now I will explain how to access or get session variable value using jQuery in asp.net.

Get or Access Session Variable value in jQuery

To get or access session variable value in jQuery we need to write the code like as shown below

var name = '<%= Session["UserName"] %>'
In above code Session["UserName"] is the value what we set in session. If you want to see it in complete example check below code


<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
var name = '<%= Session["UserName"] %>'
$('#lbltxt').text(name)
});
</script>
</head>
<body>
<label id="lbltxt" />
</body>
</html>

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

Get the latest Asp.net, C#.net, 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

10 comments :

Siva Nomula said...

I regularly view all your samples, your solutions are simple but effective.
In the above example, server tags used to retrieve Session Variable, jquery is not used.
Please correct me if i am wrong

sanju said...

Very Nice !!!

Irtekaz Ahmed Khan said...

your post interested thanks sir

Anonymous said...

TEST

Unknown said...

how to save the history

satish reddy said...

your post is nice.but my doubt is if i take the name session["username"] dynamically then how can i get the value in javascript.and first javascript code is executed next serverside code is executed

Daniel said...

I have a query, What if the session is empty? How can we handle it? Could you pls explain..?

Anonymous said...

This solution does not work....

Anonymous said...

jQuery not used in this code.
if you need to use jQuery then use the jQuery plugin to set and get the session variable.

Unknown said...

Great Post!!!
This is What I was looking For.
Thank you.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

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