LoginCancelEventArgs Klasa

Definicja

Dostarcza dane dla zdarzenia, które można anulować.

public ref class LoginCancelEventArgs : EventArgs
public class LoginCancelEventArgs : EventArgs
type LoginCancelEventArgs = class
    inherit EventArgs
Public Class LoginCancelEventArgs
Inherits EventArgs
Dziedziczenie
LoginCancelEventArgs
Pochodne

Przykłady

Poniższy przykład kodu używa LoggingIn zdarzenia, aby upewnić się, że użytkownik wprowadził dobrze sformułowany adres e-mail we UserName właściwości . Jeśli nie, LoggingIn program obsługi zdarzeń anuluje próbę logowania, ustawiając Cancel właściwość LoginCancelEventArgs obiektu na true. Następnie zostanie wyświetlony komunikat o błędzie określony we InstructionText właściwości .

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

Poniżej znajduje się plik aspx, którego można użyć do uruchomienia poprzedniego przykładu.

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
    <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="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 xmlns="http://www.w3.org/1999/xhtml" >
    <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>

Uwagi

Zdarzenie, które można anulować, jest zgłaszane, gdy składnik ma wykonać akcję, którą można anulować, taką jak logowanie do witryny sieci Web.

Klasa LoginCancelEventArgs udostępnia właściwość wskazującą Cancel , czy zdarzenie powinno zostać anulowane. LoginCancelEventArgs Obiekt jest używany z kontrolkami, które mają akcje, które można anulować, takie jak Login kontrolka, kontrolka CreateUserWizard i kontrolkaPasswordRecovery.

Konstruktory

LoginCancelEventArgs()

Inicjuje LoginCancelEventArgs nowe wystąpienie klasy z właściwością ustawioną Cancel na false.

LoginCancelEventArgs(Boolean)

Inicjuje LoginCancelEventArgs nowe wystąpienie klasy z właściwością Cancel ustawioną na określoną wartość.

Właściwości

Cancel

Pobiera lub ustawia wartość wskazującą, czy zdarzenie powinno zostać anulowane.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też