Share via


PasswordRecovery.OnUserLookupError(EventArgs) 方法

定義

引發 UserLookupError 事件。

protected:
 virtual void OnUserLookupError(EventArgs ^ e);
protected virtual void OnUserLookupError (EventArgs e);
abstract member OnUserLookupError : EventArgs -> unit
override this.OnUserLookupError : EventArgs -> unit
Protected Overridable Sub OnUserLookupError (e As EventArgs)

參數

e
EventArgs

包含事件資料的 EventArgs

範例

下列程式碼範例會定義自訂 PasswordRecovery 控制項,以覆寫 OnUserLookupError 方法,如果使用者輸入密碼確認問題的答案不正確,則變更 UserNameTitleText 屬性。

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    class CustomPasswordRecovery : PasswordRecovery
    {
        override protected void OnAnswerLookupError(EventArgs e)
        {
            QuestionTitleText = "Try again";
            TitleTextStyle.ForeColor = System.Drawing.Color.Red;
            base.OnAnswerLookupError(e);
        }
    }
    
        // Add the custom password recovery control to the page.
        void Page_Init(object sender, EventArgs e)
        {
            CustomPasswordRecovery passwordRecoveryControl = new CustomPasswordRecovery();
        
            passwordRecoveryControl.ID = "passwordRecoveryControl";
        
            PlaceHolder1.Controls.Add(passwordRecoveryControl);
        
        }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
    <p>
        <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>&nbsp;</p>

</form>
</body>
</html>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Class CustomPasswordRecovery
        Inherits PasswordRecovery
        
        Overloads Sub OnAnswerLookupError(ByVal e As EventArgs)
            QuestionTitleText = "Try again"
            TitleTextStyle.ForeColor = System.Drawing.Color.Red
            MyBase.OnAnswerLookupError(e)
        End Sub
    End Class

    ' Add the custom password recovery control to the page.
    Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        Dim passwordRecoveryControl As New CustomPasswordRecovery
        
        passwordRecoveryControl.ID = "passwordRecoveryControl"
        
        PlaceHolder1.Controls.Add(passwordRecoveryControl)
        
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
    <p>
        <asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>&nbsp;</p>

</form>
</body>
</html>

備註

OnUserLookupError當成員資格提供者找不到初始畫面上輸入的使用者名稱時,就會呼叫 方法。 預設實作會 UserLookupError 引發 事件。

引發事件會透過委派叫用此事件處理常式。 如需詳細資訊,請參閱 處理和引發事件

OnUserLookupError 方法也允許衍生類別處理事件,而不用附加委派。 這是在衍生類別中處理事件的慣用技巧。

給繼承者的注意事項

當在衍生類別中覆寫 OnUserLookupError(EventArgs) 時,請確定呼叫基底類別的 OnUserLookupError(EventArgs) 方法,使已註冊的委派能接收到事件。

適用於

另請參閱