This documentation is archived and is not being maintained.

LoginCancelEventArgs Class

Provides data for a cancelable event.

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

<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class LoginCancelEventArgs _
	Inherits EventArgs
Dim instance As LoginCancelEventArgs

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.

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, _
    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 
            Login1.InstructionText = String.Empty
        End If 
    End Sub 

End Class

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" "">

<html xmlns="" >
    <head runat="server">
    <title>ASP.NET Example</title>
        <form id="Form1" runat="server">
            <asp:Login id="Login1" 


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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0