Share via


IFieldEditor.OnSaveChange Method

Validates and saves the changes the user has made in the field property editor control.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Sub OnSaveChange ( _
    field As SPField, _
    isNewField As Boolean _
)
'Usage
Dim instance As IFieldEditor
Dim field As SPField
Dim isNewField As Boolean

instance.OnSaveChange(field, isNewField)
void OnSaveChange(
    SPField field,
    bool isNewField
)

Parameters

  • isNewField
    Type: System.Boolean

    true to indicate that the field is being created; false to indicate that an existing field is being modified.

Remarks

In general, this method sets the properties of the field parameter in accordance with values of the editor control's child controls. In some cases it may simply copy a value of a child control to a corresponding value of the field parameter. Use this method to validate the values that have been set for the editor control's child controls. This method should throw an SPException object exception if incorrect values have been written to the field parameter.

Examples

The following code shows a common structure for implementations of this method. Note:

  • This example does not use the bNewField parameter, which is typical because usually, you want the method to do exactly the same thing whether it is saving values to a new column or saving modified values to an existing column. But if you need different validation logic when creating and saving a new column than when modifying an existing one, you can test the bNewField parameter and branch accordingly.

  • This example begins by converting the field parameter back to its original custom type.

  • The example assumes that you used the recommended naming convention when you derived a custom field class from the SPField class and that you named the derived class by using the pattern field_type_nameField, such as TargetDateField. For more information about custom fields, see How to: Create a Custom Field Class.

public void OnSaveChange(SPField field, bool bNewField)
{
    field_type_nameField customTypedField = (field_type_nameField)field;

    // TODO: Validate the values of the child controls
    // of the editor control and either throw SPException
    // or write values to customTypedField.
}
Public Sub OnSaveChange(ByVal field As SPField, ByVal bNewField As Boolean)
    Dim customTypedField As field_type_nameField = CType(field, field_type_nameField)

    ' TODO: Validate the values of the child controls
    ' of the editor control and either throw SPException
    ' or write values to customTypedField.
End Sub

See Also

Reference

IFieldEditor Interface

IFieldEditor Members

Microsoft.SharePoint.WebControls Namespace

Other Resources

Custom Field Types

How to: Create a Custom Field Class

How to: Create a Custom Field Type Definition

How to: Create an Editor Control for a Field Type Property