views:

255

answers:

1

Hello,

I have an .aspx page built in SharePoint that I want to get the user name of the currently logged-in user (through ASP) and then manipulate it (using javascript). I'm getting an "object expected" error. Here's some of the code:

function checkGroupPermissions() { var loginNameVar = document.getElementById("LoginName1").innerHTML;

--snip--

}

</script> <div id="loginNameDiv" style="display:none"> <asp:LoginName runat="server" id="LoginName1"></asp:LoginName> </div>

I appreciate any and all assistance...please and thanks :)

+3  A: 

You cannot refer to an asp.net server control on the client side javascript by directly referring to its Id property. You have to use the controls ClientID property for that. Since your javascript is within your Sharepoint .aspx webpage, you can refer to it as:

document.getElementById('<%=LoginName1.ClientID %>');

See this for more details:

MSDN article on Client Script in .Net Pages

desigeek
Thanks so much! I got it working and--more importantly--I'm more educated :)
ACal
Glad it worked for you. Click the checkmark to select this as "answered".
Gurdas Nijor