0

This is html code :

<table align='right' >
<tr>
  <td><asp:Label ID="lblEmail" runat="server" Text=""></asp:Label></td> 
  <td > <div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark">
     </div></td>
</tr>
</table>

This is my function script:

<script>
        function onSignIn(googleUser) {
            var profile = googleUser.getBasicProfile();
             document.getElementById('lblEmail').InnerHTML = profile.getEmail();         
           // alert(profile.getEmail());

        };
    </script>

lblEmail can't display value, Why?

i try use alert, it display email ok.

6
  • what does profile.getEmail? Commented May 26, 2017 at 9:03
  • return value of check login with google email. Commented May 26, 2017 at 9:04
  • where is runat="server" on Label ? Commented May 26, 2017 at 9:09
  • innerHTML needs a lowercase i Commented May 26, 2017 at 9:18
  • good, it is ok. Commented May 26, 2017 at 9:20

5 Answers 5

3

Type innerHTML with a lowercase i:

<script>
       function onSignIn(googleUser) {
        var profile = googleUser.getBasicProfile();
         document.getElementById('lblEmail').innerHTML = profile.getEmail();         
       // alert(profile.getEmail());

    };
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

LOL that was a bummer :p
1

Edit 2:
Make sure your label control is outside updatepanel. If it's inside updatepanel then place your js code inside below function too.

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(function() {
    // re-bind your jQuery or Javascript events here
});

Edit 1:
Use document.getElementById('lblEmail').value instead of document.getElementById('lblEmail').InnerHTML.
Try using below code:

<script>
        function onSignIn(googleUser) {
            var profile = googleUser.getBasicProfile();
             document.getElementById('lblEmail').value = profile.getEmail();         
           // alert(profile.getEmail());

        };
    </script>

1 Comment

i had try it, but it still can't set.
0

Asp.net might have changed id. Try

document.getElementById('<%= lblEmail.ClientID %>').InnerHTML = profile.getEmail(); 

Comments

0

profile.getEmail() function return any string value ? if yes try:

var value= profile.getEmail(); $("#lblEmail").html(value);

2 Comments

Did you read the question? i try use alert, it display email ok.
Change it to $('#<%= lblEmail %>') set the ClientIDMode property to Static instead.
0

If the previous answers haven't helped, you might need to "find" it using jQuery inside the table. So like such:

var labelValue = $("table tr td").find("#lblEmail").val(); 
window.alert(labelValue);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.