Condividi tramite


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)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Public Overridable Property Value As Object
    Get
    Set
'Usage
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 get accessor just returns a null reference (Nothing in Visual Basic). There is no default implementation of the set accessor.

If the set accessor 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 set accessor and get accessor 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 set accessor or get accessor 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 set accessor or get accessor. 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 get accessor 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;
    }
}
Public Overrides Property Value() As Object
    Get
        EnsureChildControls()
        Return MyBase.Value
    End Get
    Set(ByVal value As Object)
         EnsureChildControls()
         MyBase.Value = CType(value, String)
    End Set
End Property

See Also

Reference

BaseFieldControl Class

BaseFieldControl Members

Microsoft.SharePoint.WebControls Namespace

Other Resources

How to: Create a Custom Field Type

Custom Field Types

Walkthrough: Creating a Custom Field Type