Share via


LoginCancelEventArgs.Cancel Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah acara harus dibatalkan.

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

Nilai Properti

true jika acara harus dibatalkan; jika tidak, false.

Contoh

Contoh kode berikut menggunakan LoggingIn peristiwa untuk memastikan bahwa pengguna telah memasukkan alamat email yang terbentuk dengan baik di UserName properti . Jika tidak, penanganan LoggingIn aktivitas mengatur Cancel properti ke true, dan pesan kesalahan ditampilkan. Untuk file .aspx yang dapat digunakan untuk menjalankan contoh, lihat LoginCancelEventArgs topik .

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

Keterangan

Anda dapat menggunakan Cancel properti untuk menunjukkan apakah peristiwa, seperti LoggingIn acara, LoggingOut acara, atau ChangingPassword acara, harus dibatalkan.

Berlaku untuk

Lihat juga