ClientSettingsProvider.SettingsSaved Event

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Occurs after the settings provider attempts to save the property values to the Web settings service.

Namespace:   System.Web.ClientServices.Providers
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public event EventHandler<SettingsSavedEventArgs> SettingsSaved

This event occurs after the settings provider accesses the settings service, even if the settings were not successfully saved. One reason that the provider might fail to save the settings is if the current user has been logged out. You can use the SettingsSavedEventArgs.FailedSettingsList property to determine whether any settings were not successfully saved.

This event does not occur if the settings provider cannot access the settings service, which instead causes the provider to throw a WebException.

The following example code demonstrates how to use this event to display a list of settings that were not successfully saved.

private void AttachSettingsSavedEventHandler()
{
    ((ClientSettingsProvider)Properties.Settings.Default.Providers
        ["System.Web.ClientServices.Providers.ClientSettingsProvider"])
        .SettingsSaved +=
        new EventHandler<SettingsSavedEventArgs>(Form1_SettingsSaved);
}

private void Form1_SettingsSaved(object sender,
    SettingsSavedEventArgs e)
{
    // If any settings were not saved, display a list of them.
    if (e.FailedSettingsList.Count > 0)
    {
        String failedSettings = String.Join(
            Environment.NewLine,
            e.FailedSettingsList.ToArray());

        String message = String.Format("{0}{1}{1}{2}",
            "The following setting(s) were not saved:",
            Environment.NewLine, failedSettings);

        MessageBox.Show(message, "Unable to save settings",
            MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}

.NET Framework
Available since 3.5
Return to top
Show: