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

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
C#
FB.api('/me', function (me)
 {                       
   if (me.name)
   {
     document.getElementById('auth-displayname').innerHTML = me.name;
     <%Session["fbName"] = me.name; %>
   }
 }

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

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

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
 
Comments
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
JavaScript
<%Session["fbName"] = me.name; %>

with
JavaScript
<%Session["fbName"] = auth-displayname.Value; %>
 
Share this answer
 
v2
Comments
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 asp.net 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