Share via


ProfileModule.ProfileAutoSaving 事件

定義

在頁面執行結束時發生 (如果自動設定檔儲存已啟用)。

public:
 event System::Web::Profile::ProfileAutoSaveEventHandler ^ ProfileAutoSaving;
public event System.Web.Profile.ProfileAutoSaveEventHandler ProfileAutoSaving;
member this.ProfileAutoSaving : System.Web.Profile.ProfileAutoSaveEventHandler 
Public Custom Event ProfileAutoSaving As ProfileAutoSaveEventHandler 

事件類型

範例

下列程式碼範例顯示 ProfileAutoSaving ASP.NET 應用程式之 Global.asax 檔案中包含的事件。

public void Profile_ProfileAutoSaving(object sender, ProfileAutoSaveEventArgs args)
{
  if (Profile.Cart.HasChanged)
    args.ContinueWithProfileAutoSave = true;
  else
    args.ContinueWithProfileAutoSave = false;
}
Public Sub Profile_ProfileAutoSaving(sender As Object, args As ProfileAutoSaveEventArgs)
  If Profile.Cart.HasChanged Then
    args.ContinueWithProfileAutoSave = True
  Else
    args.ContinueWithProfileAutoSave = False
  End If
End Sub

備註

如果 ProfileManager.AutomaticSaveEnabled 屬性為 true ,則會 ProfileAutoSaving 在頁面執行結束時引發 事件。 您可以使用全域事件,在 Global.asax 檔案中存取 ProfileAutoSaving ASP.NET 應用程式的 Profile_ProfileAutoSaving 類別事件 ProfileModule ,如本主題的範例所示。

方法 SettingsBase.SaveIsDirty 檢查使用者設定檔中每個 SettingsPropertyValue 屬性的屬性值,以判斷由基本類型、字串或 DateTime 物件組成的屬性是否已變更。 方法 Save 無法明確判斷自訂類別是否已變更。 您可以使用 ProfileAutoSaving 事件來判斷自訂物件是否已變更,然後繼續自動儲存已修改的物件,或取消未修改任何物件的自動儲存。

若要取消自動設定檔儲存作業,請將 ContinueWithProfileAutoSave 事件中的 ProfileAutoSaving 屬性 false 設定為 ,否則請將 ContinueWithProfileAutoSave 屬性設定為 true

事件可能有多個訂閱者 ProfileAutoSavingProfileModule將使用 屬性設定為的最後一個值 ContinueWithProfileAutoSave 。 因此,建議您在事件中 ProfileAutoSaving 明確設定 ContinueWithProfileAutoSave 屬性,無論是取消還是繼續自動儲存,因為您可能需要覆寫先前訂閱者所設定的值。

適用於

另請參閱