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

Syntax

'Declaration
Sub InitializeWithField ( _
    field As SPField _
)
'Usage
Dim instance As IFieldEditor
Dim field As SPField

instance.InitializeWithField(field)
void InitializeWithField(
    SPField field
)

Parameters

Remarks

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.

Examples

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
Public Sub InitializeWithField(ByVal field As SPField)
    If Not Page.IsPostBack Then
        If field Is Nothing Then
           ' 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.
           Dim customTypedField As field_type_nameField = CType(field, field_type_nameField)
           ' 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
    End If ' end if not a postback
End Sub ' end method

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