最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get,set session value in jqueryjavascript - Stack Overflow

programmeradmin11浏览0评论

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

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

Share Improve this question asked Apr 9, 2013 at 14:10 PriyaPriya 1,4258 gold badges23 silver badges45 bronze badges 1
  • See this:- stackoverflow./questions/2114581/… – palaѕн Commented Apr 9, 2013 at 14:17
Add a ment  | 

4 Answers 4

Reset to default 1

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.

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);
});

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

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

发布评论

评论列表(0)

  1. 暂无评论