LoginCancelEventArgs Classe

Définition

Fournit des données pour un événement annulable.

public ref class LoginCancelEventArgs : EventArgs
public class LoginCancelEventArgs : EventArgs
type LoginCancelEventArgs = class
    inherit EventArgs
Public Class LoginCancelEventArgs
Inherits EventArgs
Héritage
LoginCancelEventArgs
Dérivé

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 annule la tentative d’ouverture de session en affectant à la Cancel propriété de l’objet la LoginCancelEventArgs valeur true. Ensuite, le message d’erreur spécifié dans la InstructionText propriété s’affiche.

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

Voici le fichier .aspx qui peut être utilisé pour exécuter l’exemple précédent.

<%@ 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>

Remarques

Un événement annulable est déclenché lorsqu’un composant est sur le point d’effectuer une action qui peut être annulée, telle que la connexion à un site Web.

La LoginCancelEventArgs classe fournit la Cancel propriété pour indiquer si l’événement doit être annulé. Un LoginCancelEventArgs objet est utilisé avec des contrôles qui ont des actions annulables, telles que le Login contrôle, le CreateUserWizard contrôle et le PasswordRecovery contrôle.

Constructeurs

LoginCancelEventArgs()

Initialise une nouvelle instance de la classe LoginCancelEventArgs avec la propriété Cancel définie avec la valeur false.

LoginCancelEventArgs(Boolean)

Initialise une nouvelle instance de la classe LoginCancelEventArgs avec la propriété Cancel définie avec la valeur spécifiée.

Propriétés

Cancel

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

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à

Voir aussi