Click here to Skip to main content
15,936,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am getting name and email id of a user after he logs in via facebook to my website..
I want to add those variables in session on login form itself using javascript;
I tried following
FB.api('/me', function (me)
   if (
     document.getElementById('auth-displayname').innerHTML =;
     <%Session["fbName"] =; %>

it gives error like me (in this line: <%Session["fbName"] =; %>) does not exist in the current context etc.

How can I do this
Updated 5-Aug-13 23:21pm

Session is a server side technology. Client/Browser doesn't know anything about ASP.NET Session.

I am assuming you get the details on client side using JavaScript code. You will need to post back the page and then save the details in the Session variable on the server side.
Share this answer
Zafar Sultan 6-Aug-13 5:48am    
I have a question for you. Can't we set session value inside a JavaScript function?
Ankur\m/ 6-Aug-13 5:52am    
Already answered in your another comment. Let me know if you do not understand, I will try to elaborate it.
I am assuming "auth-displayname" is a server side hidden field. Try replacing
<%Session["fbName"] =; %>

<%Session["fbName"] = auth-displayname.Value; %>
Share this answer
Ankur\m/ 6-Aug-13 5:28am    
But how does that save data in a Session? Session is a server side technology which isn't available to the client.
Zafar Sultan 6-Aug-13 5:39am    
Why can't we?
Ankur\m/ 6-Aug-13 5:55am    
Because JavaScript knows nothing about ASP.NET Session. You have used server side tags in your JavaScript code which is called only when the code is executed by engine.
Zafar Sultan 6-Aug-13 5:58am    
OP is using postback.
Zafar Sultan 6-Aug-13 5:42am    
We can write inline server side code in javascript using <% %> block.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900