LoginName控件显示用户名。我希望显示登录用户的全名,而不是用户名。下面是我的代码。我似乎无法在后台代码中访问LoginName控件。我想知道是不是因为控件在里面。
ASPX页面:
<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>如果可能,请在C#中发布代码幕后示例...
发布于 2010-10-10 05:42:57
我找到了一条捷径:
LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;
if (loginName != null && session != null)
{
loginName.FormatString = "Full Name";
}这将在LoginView中找到LoginName控件,然后通过设置FormatString来劫持该值。我希望有一种更优雅的方式来做这件事。如果有人知道,请发给我。
发布于 2010-10-10 05:35:59
LoginView控件的行为似乎是自动的。你可能想改用不同的东西,对体验采取不同的控制方式……
您可以尝试使用,看看它是否支持您所需的灵活性。例如,它的.UserName property既是读的,也是写的。
Login1.UserName = "MY REAL NAME";显然,它也通过声明性语法支持许多功能。
<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>https://stackoverflow.com/questions/3897894
复制相似问题