LoginCancelEventArgs.Cancel 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,這個值表示是否應該取消事件。
public:
property bool Cancel { bool get(); void set(bool value); };
public bool Cancel { get; set; }
member this.Cancel : bool with get, set
Public Property Cancel As Boolean
屬性值
如果應該要取消事件則為 true,否則為 false。
範例
下列程式代碼範例會 LoggingIn 使用 事件來確保使用者已在 屬性中 UserName 輸入格式正確的電子郵件位址。 如果沒有,事件處理程式會將 LoggingInCancel 屬性設定為 true,並顯示錯誤訊息。 如需可用來執行範例的.aspx檔案,請參閱 LoginCancelEventArgs 主題。
public partial class LoginCancelEventArgscs_aspx : System.Web.UI.Page
{
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid email format.
return System.Text.RegularExpressions.Regex.IsMatch(strIn,
@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
protected void OnLoggingIn(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
if (!IsValidEmail(Login1.UserName))
{
Login1.InstructionText = "You must enter a valid email address.";
e.Cancel = true;
}
else
{
Login1.InstructionText = String.Empty;
}
}
}
Partial Class LoginCancelEventArgsvb_aspx
Inherits System.Web.UI.Page
Function IsValidEmail(ByVal strIn As String) As Boolean
' Return true if strIn is in valid email format.
Return Regex.IsMatch(strIn, _
("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
End Function
Protected Sub OnLoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
If Not IsValidEmail(Login1.UserName) Then
Login1.InstructionText = "You must enter a valid email address."
e.Cancel = True
Else
Login1.InstructionText = String.Empty
End If
End Sub
End Class
備註
您可以使用 Cancel 屬性來指出應該取消事件,例如 LoggingIn 事件、 LoggingOut 事件或 ChangingPassword 事件。