Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Value Property

BaseFieldControl.Value Property

Windows SharePoint Services 3

When overridden in a derived class, gets or sets the value of the field in the UI.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public virtual Object Value { get; set; }

Property Value

Type: System.Object
When overridden in a derived class, a Object that represents the value of the field in the UI. Typically, this is the text of a child control, such as a label or text box, that actually renders the field.

The default implementation of the getter just returns a null reference (Nothing in Visual Basic). There is no default implementation of the setter.

If the setter is overridden with logic that is appropriate for the type of child control that actually renders the field (such as label or text box); then, whenever the BaseFieldControl loads, Value is given the same value as ItemFieldValue, or it is given a default value if the field has never been set for the current list item. (ItemFieldValue is the value of the field for the SPField that has the BaseFieldControl as its FieldRenderingControl property.)

Notes to Inheritors

When you derive a class directly from BaseFieldControl, you must override the setter and getter for Value. Among other reasons, this is so that the OnLoad method can give the control the value of ItemFieldValue on first request of the page and so that it can update ItemFieldValue with the user-entered value of Value on postback.

Any override of the setter or getter must call the EnsureChildControls method (which will create any child controls if they do not already exist). This is normally the very first line of the setter or getter. However, if there would be no point to creating the child controls unless certain properties are not a null reference (Nothing in Visual Basic) and not empty strings, then you may first check for the required values before calling the method.

If the value of BaseFieldControl is changeable by users, your logic should change Value directly and then call UpdateFieldValueInItem to update ItemFieldValue. This ensures that the appropriate value-changed event occurs. (UpdateFieldValueInItem assumes that you have overridden the getter for Value.)

The following is an example of an override of the Value property when the derived field control has the same child controls, of the same types, as the parent class (or when any additional child controls declared by the derived class have constant values that are hard coded in a rendering template). Even in this situation, you should call EnsureChildControls unless you have access to the source code of the parent class's Value property and can verify that it calls EnsureChildControls. For the full example, see Walkthrough: Creating a Custom Field Type.

public override object Value
        return base.Value;
         base.Value = (String)value;

Community Additions

© 2015 Microsoft