IFieldEditor.InitializeWithField Method

Initializes the field property editor when the page loads.

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

void InitializeWithField(
	SPField field


Type: Microsoft.SharePoint.SPField

An object that instantiates a custom field (column) class that derives from the SPField class.

Use this method to perform initialization tasks such as assigning default values to the properties of the field type that are set with a text box, or populating a drop-down list box for properties that are set with a drop-down list.

On the Change Site Column and Change Column pages, field is the column whose properties are being edited. Use this method to initialize the field's (column's) editable properties with their current values. On the New Site Column and Create Column pages, field is a new object with a a null reference (Nothing in Visual Basic) value, and generally is not used in the initialization process.

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

  • This method does not perform any function if the page request is a postback. The reason for this is that you do not want to inadvertently override or cancel any changes that have been made to the property settings by the column creator or editor..

  • This example tests whether a new column is being created or an existing column is being edited, by checking to see if the parameter is a null reference (Nothing in Visual Basic).

  • If the parameter is not a null reference (Nothing in Visual Basic), it is converted back to its original custom type.

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

public void InitializeWithField(SPField field)
    if (!Page.IsPostBack)
        if (field == null)
           // TODO: It is new column, so initialize as
           // needed with data from the HTTP context or
           // with default values.
        else    // An existing column is being edited.
           field_type_nameField customTypedField = (field_type_nameField)field;
           // TODO: An existing column is being edited,
           // so initialize as needed with the current 
           // property values in customTypedField along 
           // data from the HTTP context as needed.
    }// end if not a postback
}// end method