Compartilhar via


FormComponent.ControlMode Property

Gets or sets the rendering mode for the form (display, edit, or new).

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Public Property ControlMode As SPControlMode
    Get
    Set
'Usage
Dim instance As FormComponent
Dim value As SPControlMode

value = instance.ControlMode

instance.ControlMode = value
public SPControlMode ControlMode { get; set; }

Property Value

Type: Microsoft.SharePoint.WebControls.SPControlMode

Exceptions

Exception Condition
[SPException]

Thrown when trying to get the ControlMode property when there is no valid ControlMode in the parent chain control, no ControlMode property on the page, no ControlMode in the parent chain, no ControlMode property on the page, and when the context is not design time.

[ArgumentException]

Thrown when trying to set the ControlMode to SPControlMode.Invalid.

Remarks

The control can define its ControlMode property in three ways, listed in order of precedence:

  • On the control.

  • On the parent chain control, which is also a FormComponent object.

  • Based on the ControlMode property set on the page.

If a control does not specify ControlMode on the control itself, it traverses the parent chain to find a control that has set ControlMode. If no parent control is a FormComponent object that has ControlMode set, the ControlMode property of the page is used.

If, after these conditions are checked and the ControlMode is still unknown, and the context is design time, then a default of display mode is used.

Note

Unexpected behavior may occur when you set the ControlMode and ItemContext in OnInit (the ControlMode may be mistakenly set to the new mode). Walking up the tree to find the ControlMode fails because the control has not been added to the control tree yet and its parent control is null.

For all FormComponent controls, create the ItemContext as early as possible so that child controls can get the SPContext object before the controls are added into control tree of the page (before Init).

To find the control mode from parent control while parent control is null, retrieve the control mode from itemContext.FormContext.FormMode.

See Also

Reference

FormComponent Class

FormComponent Members

Microsoft.SharePoint.WebControls Namespace