LoginCancelEventArgs.Cancel Property

 

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

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

Public Property Cancel As Boolean

Property Value

Type: System.Boolean

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

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.

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

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

.NET Framework
Available since 2.0
Return to top
Show: