LoginStatus.OnLoggingOut(LoginCancelEventArgs) 方法

定義

當使用者按一下 LoggingOut 控制項上的登出連結時,引發 LoginStatus 事件。

protected:
 virtual void OnLoggingOut(System::Web::UI::WebControls::LoginCancelEventArgs ^ e);
protected virtual void OnLoggingOut (System.Web.UI.WebControls.LoginCancelEventArgs e);
abstract member OnLoggingOut : System.Web.UI.WebControls.LoginCancelEventArgs -> unit
override this.OnLoggingOut : System.Web.UI.WebControls.LoginCancelEventArgs -> unit
Protected Overridable Sub OnLoggingOut (e As LoginCancelEventArgs)

參數

e
LoginCancelEventArgs

包含事件資料的 LoginCancelEventArgs

範例

下列程式碼範例會將事件處理常式附加至 OnLoggingOut 事件。 事件處理常式會更新表單上的欄位,然後取消登出嘗試。

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void LoginStatus1_LoggingOut(Object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
    {
        Message.Text = "LoggingOut event. Don't go away now.";
        e.Cancel = true;
    }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="FORM1" runat="server">
            <asp:LoginStatus id="LoginStatus1" 
              runat="server" 
              onloggingout="LoginStatus1_LoggingOut">
            </asp:LoginStatus>
            <p></p>
            <asp:Literal id="Message" 
              runat="server" />
        </form>
    </body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub LoginStatus1_LoggingOut(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
    Message.Text = "LoggingOut event. Don't go away now."
    e.Cancel = True
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="FORM1" runat="server">
            <asp:LoginStatus id="LoginStatus1" 
              runat="server" 
              onloggingout="LoginStatus1_LoggingOut">
            </asp:LoginStatus>
            <p></p>
            <asp:Literal id="Message" 
              runat="server" />
        </form>
    </body>
</html>

備註

使用 LoggingOut 事件來提供額外的處理,例如在使用者登出網站之前清除每個使用者的資料。 OnLoggingOut您可以取消事件,以便讓使用者選擇儲存資料,例如購物車或資料庫變更,再離開網站。

如需處理事件的詳細資訊,請參閱 處理和引發事件

OnLoggingOut 方法也允許衍生類別處理事件,而不用附加委派。 這是在衍生類別中處理事件的慣用技巧。

給繼承者的注意事項

當在衍生類別中覆寫 OnLoggingOut(LoginCancelEventArgs) 時,請確定呼叫基底類別的 OnLoggingOut(LoginCancelEventArgs) 方法,使已註冊的委派能接收到事件。

適用於

另請參閱