EditorPart.SyncChanges Method

Note: This method is new in the .NET Framework version 2.0.

Retrieves the property values from a WebPart control for its associated EditorPart control.

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in system.web.dll)

public abstract void SyncChanges ()
public abstract void SyncChanges ()
public abstract function SyncChanges ()

The SyncChanges method is a critical method on an EditorPart control. It is defined as an abstract method in the EditorPart class, and must be implemented by inherited controls. The purpose of the method is to retrieve the current values from the WebPart control referenced in the WebPartToEdit property, and update the fields in the EditorPart control with those values so a user can edit them.

The SyncChanges method is called whenever the values in the associated WebPart control might have changed. For every EditorPart control, the EditorZoneBase zone that contains the control calls the SyncChanges method immediately after calling the ApplyChanges method, so that the values in the EditorPart control are always synchronized with the values in the associated WebPart control. Another case where the SyncChanges method is called is when a WebPart control is entering edit mode.


The SyncChanges method is not called after the ApplyChanges method if that method returns false, because in that case, an error has occurred.

Notes to Inheritors A class that derives from the EditorPart class must implement the SyncChanges method. The implemented method gets a reference to the associated control using the WebPartToEdit property, and then updates the EditorPart control with the property values from the associated WebPart control.

The following code example demonstrates how to implement the SyncChanges method in a custom EditorPart control. For the full code required to run the example, see the Example section of the EditorPart class overview.

The first part of the code example demonstrates the implementation of the SyncChanges method in the custom EditorPart class named TextDisplayEditorPart. This method gets a reference to the associated TextDisplayWebPart control using the WebPartToEdit property. It then gets the value of the TextDisplayWebPart.FontStyle property, and updates which item is selected in the drop-down list control (referenced by the TextDisplayEditorPart.PartContentFontStyle property) on the custom EditorPart control.

public override void SyncChanges()
  TextDisplayWebPart part = 
  String currentStyle = part.FontStyle;

  // Select the current font style in the drop-down control.
  foreach (ListItem item in PartContentFontStyle.Items)
    if (item.Value == currentStyle)
      item.Selected = true;

The second part of the code example shows how the associated WebPart control, TextDisplayWebPart, creates a collection of associated EditorPart controls (in this case, there is only one EditorPart control named TextDisplayEditorPart in the collection) in its implementation of the CreateEditorParts method. This method is executed when the TextDisplayWebPart control enters edit mode.

public override EditorPartCollection CreateEditorParts()
  ArrayList editorArray = new ArrayList();
  TextDisplayEditorPart edPart = new TextDisplayEditorPart();
  edPart.ID = this.ID + "_editorPart1";
  EditorPartCollection editorParts = 
    new EditorPartCollection(editorArray);
  return editorParts;

public override object WebBrowsableObject
  get { return this; }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0