LoginCancelEventArgs.Cancel Property


Gets or sets a value indicating whether the event should be canceled.

 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

Property Value

true if the event should be canceled; otherwise, false.


The following code example uses the LoggingIn event to ensure that the user has entered a well-formed email address in the UserName property. If not, the LoggingIn event handler sets the Cancel property to true, and an error message is displayed. For an .aspx file that can be used to run the example, see the LoginCancelEventArgs topic.

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

End Class


You can use the Cancel property to indicate whether an event, such as the LoggingIn event, the LoggingOut event, or the ChangingPassword event, should be canceled.

Applies to

See also