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 Overrides Sub SyncChanges()
Dim part As TextDisplayWebPart = CType(WebPartToEdit, _
TextDisplayWebPart)
Dim currentStyle As String = part.FontStyle
' Select the current font style in the drop-down control.
Dim item As ListItem
For Each item In PartContentFontStyle.Items
If item.Value = currentStyle Then
item.Selected = True
Exit For
End If
Next item
End Sub
|
|
public override void SyncChanges()
{
TextDisplayWebPart part =
(TextDisplayWebPart)WebPartToEdit;
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;
break;
}
}
}
|
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 Overrides Function CreateEditorParts() _
As EditorPartCollection
Dim editorArray As New ArrayList()
Dim edPart as New TextDisplayEditorPart()
edPart.ID = Me.ID & "_editorPart1"
editorArray.Add(edPart)
Dim editorParts As New EditorPartCollection(editorArray)
Return editorParts
End Function
Public Overrides ReadOnly Property WebBrowsableObject() _
As Object
Get
Return Me
End Get
End Property
|
|
public override EditorPartCollection CreateEditorParts()
{
ArrayList editorArray = new ArrayList();
TextDisplayEditorPart edPart = new TextDisplayEditorPart();
edPart.ID = this.ID + "_editorPart1";
editorArray.Add(edPart);
EditorPartCollection editorParts =
new EditorPartCollection(editorArray);
return editorParts;
}
public override object WebBrowsableObject
{
get { return this; }
}
|