开发者

Display Full Name Instead of Username in LoginName Control

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开发者_Python百科" 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...


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.


The LoginView control seems somewhat automatic in its behaviour. You may want to switch to using something different and take a different kind of control over the experience...

You might try the Login control instead, to see if it allows for the flexbility you require. For example its .UserName property is both read/write.

Login1.UserName = "MY REAL NAME";

Apparently it supports many features through declarative syntax too.

<asp:Login
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderPadding="integer"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CreateUserIconUrl="uri"
    CreateUserText="string"
    CreateUserUrl="uri"
    CssClass="string"
    DestinationPageUrl="uri"
    DisplayRememberMe="True|False"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    FailureAction="Refresh|RedirectToLoginPage"
    FailureText="string"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
               Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    HelpPageIconUrl="uri"
    HelpPageText="string"
    HelpPageUrl="uri"
    ID="string"
    InstructionText="string"
    LoginButtonImageUrl="uri"
    LoginButtonText="string"
    LoginButtonType="Button|Image|Link"
    MembershipProvider="string"
    OnAuthenticate="Authenticate event handler"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnLoggedIn="LoggedIn event handler"
    OnLoggingIn="LoggingIn event handler"
    OnLoginError="LoginError event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    Orientation="Horizontal|Vertical"
    PasswordLabelText="string"
    PasswordRecoveryIconUrl="uri"
    PasswordRecoveryText="string"
    PasswordRecoveryUrl="uri"
    PasswordRequiredErrorMessage="string"
    RememberMeSet="True|False"
    RememberMeText="string"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    TextLayout="TextOnLeft|TextOnTop"
    TitleText="string"
    ToolTip="string"
    UserName="string"
    UserNameLabelText="string"
    UserNameRequiredErrorMessage="string"
    Visible="True|False"
    VisibleWhenLoggedIn="True|False"
    Width="size"
>
        <CheckBoxStyle />
        <FailureTextStyle />
        <HyperLinkStyle />
        <InstructionTextStyle />
        <LabelStyle />
        <LayoutTemplate>
            <!-- child controls -->
        </LayoutTemplate>
        <LoginButtonStyle />
        <TextBoxStyle />
        <TitleTextStyle />
        <ValidatorTextStyle />
</asp:Login>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜