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. |
|||
|
|||
10 comments :
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
Very Nice !!!
your post interested thanks sir
TEST
how to save the history
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
I have a query, What if the session is empty? How can we handle it? Could you pls explain..?
This solution does not work....
jQuery not used in this code.
if you need to use jQuery then use the jQuery plugin to set and get the session variable.
Great Post!!!
This is What I was looking For.
Thank you.
Note: Only a member of this blog may post a comment.