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

void OnSaveChange(
	SPField field,
	bool isNewField
)

Parameters

field
Type: Microsoft.SharePoint.SPField

The field (column) whose properties are being saved.

isNewField
Type: System.Boolean

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

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.

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.
}
Show:
© 2015 Microsoft