共用方式為


PasswordRecovery.OnAnswerLookupError(EventArgs) 方法

定義

引發 AnswerLookupError 事件。

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

參數

e
EventArgs

包含事件資料的 EventArgs

範例

下列程式代碼範例會建立自定義 PasswordRecovery 控件,以覆寫 OnAnswerLookupError 方法,如果使用者輸入密碼確認問題的答案不正確,則會變更 QuestionTitleText 屬性。

<%@ 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>

備註

OnAnswerLookupError當使用者對密碼復原確認問題的解答不符合網站數據存放區中儲存的答案時,就會呼叫 方法。 默認實作會 AnswerLookupError 引發 事件。

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

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

給繼承者的注意事項

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

適用於

另請參閱