LoginCancelEventArgs 類別

定義

提供可取消事件的資料。

public ref class LoginCancelEventArgs : EventArgs
public class LoginCancelEventArgs : EventArgs
type LoginCancelEventArgs = class
    inherit EventArgs
Public Class LoginCancelEventArgs
Inherits EventArgs
繼承
LoginCancelEventArgs
衍生

範例

下列程式碼範例會使用 LoggingIn 事件,以確保使用者已在 屬性中 UserName 輸入格式正確的電子郵件地址。 如果沒有, LoggingIn 事件處理常式會將 物件的 屬性 LoginCancelEventArgs 設定 Canceltrue ,以取消登入嘗試。然後會顯示 屬性中指定的 InstructionText 錯誤訊息。

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

以下是可用來執行上述範例的 .aspx 檔案。

<%@ Page Language="C#" CodeFile="LoginCancelEventArgs.cs" Inherits="LoginCancelEventArgscs_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="Form1" runat="server">
            <asp:Login id="Login1" 
              runat="server" 
              onloggingin="OnLoggingIn">
            </asp:Login>
        </form>
    </body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="LoginCancelEventArgs.vb" Inherits="LoginCancelEventArgsvb_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="Form1" runat="server">
            <asp:Login id="Login1" 
              runat="server" 
              onloggingin="OnLoggingIn">
            </asp:Login>
        </form>
    </body>
</html>

備註

當元件即將執行可取消的動作時,就會引發可取消的事件,例如登入網站。

類別 LoginCancelEventArgs 提供 Cancel 屬性,指出是否應該取消事件。 LoginCancelEventArgs物件會與具有可取消動作的控制項搭配使用,例如 Login 控制項、 CreateUserWizard 控制項和 PasswordRecovery 控制項。

建構函式

LoginCancelEventArgs()

LoginCancelEventArgs 屬性設定成 false 來初始化 Cancel 類別的新執行個體。

LoginCancelEventArgs(Boolean)

LoginCancelEventArgs 屬性設定成指定值,初始化 Cancel 類別的新執行個體。

屬性

Cancel

取得或設定值,這個值表示是否應該取消事件。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱