LoginCancelEventArgs.Cancel Proprietà

Definizione

Ottiene o imposta un valore che indica se l'evento debba essere annullato.

public:
 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

Valore della proprietà

true se l'evento deve essere annullato. In caso contrario, false.

Esempio

Nell'esempio di codice seguente viene usato l'evento LoggingIn per assicurarsi che l'utente abbia immesso un indirizzo di posta elettronica ben formato nella UserName proprietà. In caso contrario, il LoggingIn gestore eventi imposta la Cancel proprietà su truee viene visualizzato un messaggio di errore. Per un file aspx che può essere usato per eseguire l'esempio, vedere l'argomento LoginCancelEventArgs .

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

Commenti

È possibile usare la Cancel proprietà per indicare se un evento, ad esempio l'evento, l'evento LoggingIn o l'evento LoggingOutChangingPassword , deve essere annullato.

Si applica a

Vedi anche