I am getting session value is undefined .
window.onload = function () {
var mySessionVar = '<%#HttpContext.Current.Session("lnUserID")%>';
alert(mySessionVar.value);
}
var mySessionVar = '<%#HttpContext.Current.Session("lnUserID")%>';
alert(mySessionVar.value);
}
how to get session value using javascript


Joginder BangerRank #360 · 7K reputationPosted Nov 28, 2014, 12:58 AM EST
var mysessionvar='<%=Session("lnUserID")%>'
Khargesh RajputRank #616 · 3.9K reputationPosted Nov 28, 2014, 1:02 AM EST
it gives
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
error
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Nov 28, 2014, 1:24 AM EST
as i think "The session is a server side thing. you cannot access it using java scripts directly. You can write an Http handler (that will share the sessionid if any) and return the value from there using
$.ajaxor java scripts"so what u r doing is only correct.
Khargesh RajputRank #616 · 3.9K reputationPosted Nov 28, 2014, 1:27 AM EST
I am using mysession.value but it solve using .tostring()
window.onload = function () {
var mySessionVar = '<%#Session("lnUserID")%>';
alert(mySessionVar.toString());
}
Thanks for reply