When digging around in the SharePoint WebControls on showing some field properties on a pagelayout I found some interesting stuff.
First of all I thought the SharePoint webcontrol ‘FieldDescription’ would show the description of the field. At MSDN the FieldDescription class was described as
‘Represents the description metadata of a field.’
Any context is missing here.
After looking around a little bit more some context was found at the description of the Render method:
This member overrides TemplateBasedControl.Render(HtmlTextWriter).
Ah, so this webcontrol is used in template based controls. In the SharePoint root folder some references to this control were found in DefaultTemplates.ascx and SharePoint_Publishing_defaultformtemplates.ascx.
Stubborn as I am I just put this control on a page layout to check if anything will be rendered, but nothing was.
The FieldProperty control
‘Represents a property of a field; that is, a column, on a list.’
This is what I’m actually looking for!
The control is very easy to use:
<SharePointWebControls:FieldProperty FieldName="Title" PropertyName="Required" runat="server" />
The FieldName is the static (internal) field name and the PropertyName can any of the properties of a field.
The FieldProperty control will return the values set in the UI or in XML, dependent on how the field is created.
In the picture below the results are shown of the property values of three columns:
- SingleLineOfTextField: single line of text field, created in xml, not required, created in a group, ShowInNewForm set to TRUE.
- UICreated: single line of text field, manually created directly at list level, required
- UICreatedSiteColumn: single line of text field, manually created in the site columns gallery and added to the list, required and stored in a group
The value of the ShowInNewForm attribute isn’t returned, so probably not all field elements can be used.
The FieldProperty control can be used to show values of field properties on a page, but not all. In the above example the ShowInNewForm isn’t exactly useful to show on a page, but ok.
Be aware of the value of the description property returned: this is the value on the list, not the site columns itself.