开发者

Set failuretext on custom login layout template

Im writing my own login layout template. However I can not set the failuretext literal when a user fails to login. Iv googled but I cant find an answer..

I have tried to set the FailureText attribute on the login control with no result..

control:

<asp:Login ID="Login" runat="server" DisplayRememberMe="false" OnLoggedIn="OnLoggedIn" OnLoggingIn="OnLoggingIn" OnLoginError="OnLoginError">
    <LayoutTemplate>
        <table>
开发者_StackOverflow            // 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>

Codebehind:

    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";


I had this same issue and ended up having two literals in the login control template. One with ID=FailureText that the control uses itself and another with ID=CustomFailureText that I use in code behind.

Your code will become like this:

protected void OnLoginError(object sender, EventArgs e)
{
    Login.FindControl("CustomFailureText").Text = "Det gick inte att logga in.";
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜