.NET Framework Class Library LoginCancelEventArgs Class Provides data for a cancelable event.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
Public Class LoginCancelEventArgs _
Inherits EventArgs
public class LoginCancelEventArgs : EventArgs
public ref class LoginCancelEventArgs : public EventArgs
type LoginCancelEventArgs =
class
inherit EventArgs
end
The LoginCancelEventArgs type exposes the following members.

Constructors

Properties
|
| Name | Description |
|---|
.gif) | Cancel | Gets or sets a value indicating whether the event should be canceled. | Top

Methods

Remarks
A cancelable event is raised when a component is about to perform an action that can be canceled, such as logging on to a Web site. The LoginCancelEventArgs class provides the Cancel property to indicate whether the event should be canceled. A LoginCancelEventArgs object is used with controls that have cancelable actions, such as the Login control, the CreateUserWizard control, and the PasswordRecovery control.

Examples
The following code example uses the LoggingIn event to ensure that the user has entered a well-formed e-mail address in the UserName property. If not, the LoggingIn event handler cancels the logon attempt by setting the Cancel property of the LoginCancelEventArgs object to true.Then the error message specified in the InstructionText property is displayed.
Partial Class LoginCancelEventArgsvb_aspx
Inherits System.Web.UI.Page
Function IsValidEmail(ByVal strIn As String) As Boolean
' Return true if strIn is in valid e-mail 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 e-mail address."
e.Cancel = True
Else
Login1.InstructionText = String.Empty
End If
End Sub
End Class
public partial class LoginCancelEventArgscs_aspx : System.Web.UI.Page
{
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail 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 e-mail address.";
e.Cancel = true;
}
else
{
Login1.InstructionText = String.Empty;
}
}
}
The following is the .aspx file that can be used to run the preceding example.
<%@ 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 >
<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="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 >
<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>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework LoginCancelEventArgs, classe Fournit des données pour un événement annulable.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public Class LoginCancelEventArgs _
Inherits EventArgs
public class LoginCancelEventArgs : EventArgs
public ref class LoginCancelEventArgs : public EventArgs
type LoginCancelEventArgs =
class
inherit EventArgs
end
Le type LoginCancelEventArgs expose les membres suivants.

Constructeurs

Propriétés
|
| Nom | Description |
|---|
.gif) | Cancel | Obtient ou définit une valeur indiquant si l'événement doit être annulé. | Début

Méthodes

Notes
Un événement annulable est déclenché lorsqu'un composant va exécuter une action qui peut être annulée, par exemple la connexion à un site Web. La classe LoginCancelEventArgs fournit la propriété Cancel pour indiquer si l'événement doit être annulé. Un objet LoginCancelEventArgs est utilisé avec les contrôles qui ont des actions annulables, par exemple les contrôles Login, CreateUserWizard et PasswordRecovery.

Exemples
L'exemple de code suivant utilise l'événement LoggingIn pour vérifier que l'utilisateur a entré une adresse de messagerie correcte dans la propriété UserName. Si tel n'est pas le cas, le gestionnaire d'événements LoggingIn annule la tentative de connexion en affectant la valeur true à la propriété Cancel de l'objet LoginCancelEventArgs. Ensuite, le message d'erreur spécifié dans la propriété InstructionText s'affiche.
Partial Class LoginCancelEventArgsvb_aspx
Inherits System.Web.UI.Page
Function IsValidEmail(ByVal strIn As String) As Boolean
' Return true if strIn is in valid e-mail 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 e-mail address."
e.Cancel = True
Else
Login1.InstructionText = String.Empty
End If
End Sub
End Class
public partial class LoginCancelEventArgscs_aspx : System.Web.UI.Page
{
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid e-mail 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 e-mail address.";
e.Cancel = true;
}
else
{
Login1.InstructionText = String.Empty;
}
}
}
L'élément ci-après représente le fichier .aspx permettant d'exécuter l'exemple précédent.
<%@ 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 >
<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="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 >
<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>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
RéférenceAutres ressources
|