共用方式為


BaseFieldControl.Value Property

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)

Syntax

Public Overridable Property Value As Object
    Get
    Set

Dim instance As BaseFieldControl
Dim value As Object

value = instance.Value

instance.Value = value
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.

Remarks

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

Examples

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
{
    get
    {
        EnsureChildControls();
        return base.Value;
    }
    set
    {
         EnsureChildControls();
         base.Value = (String)value;
    }
}

See Also

Reference

BaseFieldControl Class

BaseFieldControl Members

Microsoft.SharePoint.WebControls Namespace

Other Resources

Patterns of Custom Field Rendering

Custom Field Types

Walkthrough: Creating a Custom Field Type