Reputation: 1425
I want to set session variable using javascript/jquery in my apsx page. Afterwards,I want to use that session variable in other page using jquery. Can anyone help me for this?
Thanks,
Priya
Upvotes: 0
Views: 24643
Reputation: 4550
You have two cases here ,
1) If you want to set the value of Session in client side on the page load it self you can use the hidden field to pass on the client side .
2) If you want to set the value on the client side without going to back to post back , you can opt for the AJAX method
Upvotes: 0
Reputation: 797
You can set the session variable value in hidden field when page is initially loaded like this:
<asp:HiddenField ID="HDSessionValue" runat="server" Value'<%#Session["CustomerID"]'/>
Now you can easily get the value from jquery or javascript like this:
$(document).ready(function(){
var SessionValue=$('#HDSessionValue').val();
alert(SessionValue);
});
Upvotes: 1
Reputation: 64466
you can assign the value of session
variable to JS
variable but to assign a value to session
variable you need something like ajax
working on server side
Upvotes: 0
Reputation: 11830
You cannot set directly with javascript you need server side code for it. you can make an ajax call and pass parameter and set session there.
Upvotes: 1