我正在编写自己的登录布局模板。但是,当用户登录失败时,我无法设置failuretext文字。我谷歌了一下,但我找不到答案。
我尝试在登录控件上设置FailureText属性,但没有结果..
控制:
<asp:Login ID="Login" runat="server" DisplayRememberMe="false" OnLoggedIn="OnLoggedIn" OnLoggingIn="OnLoggingIn" OnLoginError="OnLoginError">
<LayoutTemplate>
<table>
// Some other username and password controls here, buttons etc.
<tr>
<td>
<asp:Literal id="FailureText" runat="server"></asp:Literal>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
后台代码:
protected void OnLoginError(object sender, EventArgs e)
{
Login.FailureText = "Det gick inte att logga in.";
}
Label CustomFailureLabel = Login.FindControl("YourLabelID") as Label;
CustomFailureLabel.Text = "Your Failure Text";
我遇到了同样的问题,最终在登录控件模板中有两个文字。一个是控件本身使用的ID=FailureText
,另一个是我在后面代码中使用的ID=CustomFailureText
。
你的代码将变成这样:
protected void OnLoginError(object sender, EventArgs e)
{
Login.FindControl("CustomFailureText").Text = "Det gick inte att logga in.";
}