这是我的JavaScript
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
var user_email = response.authResponse.id;
FB.api('/me', function (me) {
if (me.name) {
document.getElementById('auth-displayname').innerHTML = me.name;
}
});
}
这里我想将var user_email
分配给asp标签控件。我该怎么办?
答案 0 :(得分:0)
您必须使用ClientID
属性来获取客户端元素:
<asp:Label ID="lblfbid" runat="server" ></asp:Label>
...
<script>
...
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
var user_email = response.authResponse.id;
FB.api('/me', function (me) {
if (me.name) {
// Just for client-side
document.getElementById('<%=lblfbid.ClientID %>').innerHTML = user_email;
// Send user_email on server-side ($.post is from jQuery) for some reason:
$.post(
'/MyService.asmx/SendUserEmail',
{ userEmail: user_email },
function() { /* do something on success */ });
}
});
}
...
</script>
MyService.asmx.cs
:
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public void SendUserEmail(userEmail userEmail)
{
// do some stuff with userEmail
}
}