Headshot
Headshot

Reputation: 452

How to read object of Session ASP.net in Javascript?

I have a session in ASP, it's object. Now, I want read some value of object in client , I known Session live in Server , at client only read it.

enter image description here

 var obj = UserModBus.Login(user_name, pass_word);
        if (obj != null)
        {
            HttpContext.Current.Session["OBJ"] = obj;
        }

In my page using javascript

 <script type="text/javascript" charset="utf-8">
    $(document).ready(function () {        
var full_name = '((QLNT.DATA.USER_MOD) Session["OBJ"]).FULL_NAME%>';
var birth_day = '((QLNT.DATA.USER_MOD) Session["OBJ"]).BIRTH_DAY%>';
        window.onload = function () {
            alert(full_name + birth_day);
        }
    });
</script>

But it's not working. Can you give me some advice to solve it?

Thank you guys.

Upvotes: 2

Views: 233

Answers (1)

brandon-irl
brandon-irl

Reputation: 115

Is it because you are missing the <%=?

...
var full_name = '<%=((QLNT.DATA.USER_MOD) Session["OBJ"]).FULL_NAME%>';
var birth_day = '<%=((QLNT.DATA.USER_MOD) Session["OBJ"]).BIRTH_DAY%>';
...

Upvotes: 3

Related Questions