This topic has not yet been rated - Rate this topic

RequiredFieldMessage Class

Represents a control that displays a message that a field is a required input.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class RequiredFieldMessage : FormComponent
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
RequiredFieldMessage
Description

The RequiredFieldMessage sealed class inherits from the Microsoft.SharePoint.WebControls.FormComponent class which is the foundational control for form and field rendering controls. The RequiredFieldMessage control is responsible for the rendering of the message displayed when a user does not enter required values into an arbitrary SharePoint Field Control. 

First, the control is going to several conditional tests on the provided base FieldControlCollection. The enumerated FieldControl objects are checked for:

To be of type Microsoft.SharePoint.WebControls.BaseFieldControl 

Are not null 

The BaseFieldControl.Field.Required property is set to true 

The visibility will be tested both with the Control Visible property as well as SPControlMode.Display property to ensure that the field is actually visible

The Usage Scenario

You typically find RequiredFieldMessage usage limited to internal calls within SharePoint list related componets, heavy representation can be found within classes such as DataFormWebPart and ListFormWebPart. However, it is possible to programmatically use the control to manipulate validation interfaces in combination with various other SharePoint objects.

The below shows casting the current instance of a class to a ListFormWebPart then retrieiving the ListFormWebPart.ToolBar property to hydrate a ToolBar object. Following, we are testing the context SPControlMode to make certain we are not in display mode (since the RequiredFieldMessage is displayed when input conditions are not met), then adding a new RequiredFieldMessage control to the RightButtons (RepeatedControls) of the ToolBar object. 

C# Code Example 

ToolBar toolbar = ((ListFormWebPart)this).Toolbar; 
if (!Equals(SPContext.Current.FormContext.FormMode, SPControlMode.Display)) 

RequiredFieldMessage rfm = new RequiredFieldMessage(); 
toolbar.RightButtons.Controls.Add(rfm); 
}

Visual Basic .NET Code Example

Dim toolbar As ToolBar = DirectCast(Me, ListFormWebPart).Toolbar
If Not Equals(SPContext.Current.FormContext.FormMode, SPControlMode.Display) Then
Dim rfm As New RequiredFieldMessage()
toolbar.RightButtons.Controls.Add(rfm)
End If toolbar.RightButtons.Controls.Add(rfm)
End If
 
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com