IFieldEditor.InitializeWithField Method (Microsoft.SharePoint.WebControls)
Initializes the field property editor when the page loads.

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

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

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

Parameters

field

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

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 null value, and generally is not used in the initialization process.

Example

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 null.

  • If the parameter is not null, 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 Custom Field Classes.

C#
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
See Also

Tags :


Page view tracker