PasswordRecovery.OnUserLookupError(EventArgs) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
引發 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)
參數
範例
下列程式代碼範例會定義自定義 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> </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> </p>
</form>
</body>
</html>
備註
OnUserLookupError當成員資格提供者找不到初始畫面上輸入的用戶名稱時,就會呼叫 方法。 默認實作會 UserLookupError 引發 事件。
引發事件會透過委派叫用此事件處理常式。 如需詳細資訊,請參閱 處理和引發事件。
OnUserLookupError 方法也允許衍生類別處理事件,而不用附加委派。 這是在衍生類別中處理事件的慣用技巧。
給繼承者的注意事項
當在衍生類別中覆寫 OnUserLookupError(EventArgs) 時,請確定呼叫基底類別的 OnUserLookupError(EventArgs) 方法,使已註冊的委派能接收到事件。