LoginCancelEventArgs.Cancel Propriété

Définition

Obtient ou définit une valeur indiquant si l'événement doit être annulé.

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

Valeur de propriété

true si l'événement doit être annulé ; sinon, false.

Exemples

L’exemple de code suivant utilise l’événement LoggingIn pour s’assurer que l’utilisateur a entré une adresse e-mail bien formée dans la UserName propriété . Si ce n’est pas le cas, le LoggingIn gestionnaire d’événements définit la Cancel propriété sur true, et un message d’erreur s’affiche. Pour obtenir un fichier .aspx qui peut être utilisé pour exécuter l’exemple, consultez la LoginCancelEventArgs rubrique .

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

Remarques

Vous pouvez utiliser la Cancel propriété pour indiquer si un événement, tel que l’événement LoggingIn , l’événement LoggingOut ou l’événement ChangingPassword , doit être annulé.

S’applique à

Voir aussi