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

Khargesh RajputPosted Nov 28, 2014, 6:27 AM
I am using mysession.value but it solve using .tostring()
window.onload = function () {
var mySessionVar = '<%#Session("lnUserID")%>';
alert(mySessionVar.toString());
}
Thanks for reply
Manish Kumar ChoudharyPosted Nov 28, 2014, 6:24 AM
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 RajputPosted Nov 28, 2014, 6:02 AM
it gives
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
error
Joginder BangerPosted Nov 28, 2014, 5:58 AM
var mysessionvar='<%=Session("lnUserID")%>'