Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Full Name Instead of Username in LoginName Control

Tags:

c#

asp.net

The LoginName control displays the Username. I would like to display the Full Name of the user logged in rather than the Username. Below is my code. I cannot seem to access the LoginName control in code behind. I am wondering if it because the control is in .

ASPX Page:

<asp:loginview id="HeadLoginView" runat="server" enableviewstate="false">
    <AnonymousTemplate>
        [ <a id="HeadLoginStatus" runat="server" href="login">Log In</a> ]
    </AnonymousTemplate>
    <LoggedInTemplate>
        Welcome <span class="bold">
            <asp:LoginName ID="HeadLoginName" runat="server" />
        </span>! [
        <asp:LoginStatus ID="HeadLoginStatus" runat="server" 
            LogoutAction="Redirect" LogoutPageUrl="~/home"
            LogoutText="Log Out" />
        ]
    </LoggedInTemplate>
</asp:loginview>

Please post code behind examples in C# if possible...

like image 882
Tyson Nero Avatar asked Oct 09 '10 21:10

Tyson Nero


1 Answers

I was able to figure out a short cut:

LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;

        if (loginName != null && session != null)
        {
            loginName.FormatString = "Full Name";
        }

This finds the LoginName control within the LoginView, then hijacks the value by setting FormatString. I wish there was a more elegant way of doing this. If anyone knows, please send it my way.

like image 135
Tyson Nero Avatar answered Sep 22 '22 21:09

Tyson Nero