What are Field Controls?
From Sense/Net 6.0 Wiki
Contents |
[edit] Overview
Field Contols are the main building blocks of Content views. They generate the HTML controls responsible for the input or output of the displayed Content's fields. Implemented as ASP.NET custom controls, they can be used in the ascx source of the Content view as such.
As an example, take a look at the following code fragment. This is the new.ascx Content view for the Car Content Type, responsible for creating a new instance of that type (in database terms, a new record). It contains the appropriate Field controls for each field of the Content.
(/Root/System/ContentViews/Car/new.ascx)
<sn:ErrorView ID="ErrorView1" runat="server" /> <sn:ShortText ID="ShortText1" runat="server" FieldName="Name" /> <sn:WholeNumber ID="Integer1" runat="server" FieldName="Index" /> <sn:ShortText ID="ShortText3" runat="server" FieldName="Make" /> <sn:ShortText ID="ShortText4" runat="server" FieldName="Model" /> <sn:DropDown ID="Choice1" runat="server" FieldName="Style" /> <sn:ShortText ID="ShortText5" runat="server" FieldName="EngineSize" /> <sn:ShortText ID="ShortText6" runat="server" FieldName="Power" /> <sn:ShortText ID="ShortText7" runat="server" FieldName="Price" /> <sn:LongText ID="LongText1" runat="server" FieldName="Description" />
[edit] Public properties
In addition to the standard properties every ASP.NET server control shares, Field Controls provide several other ways to control their behavior. The most important properties are the following:
- Title - The field's title. Its value is inherited from the Content Type Definition, but can be overridden.
- Description - The field's description. It's inherited similarly.
- ReadOnly - If true, even an input control will render disabled. A read-only field will generate a read-only control, but it can also be set at control level manually.
- Inline - If true, the control is rendered naked, without its Title and Description.
- Width - Width of the control in pixels.
- RenderMode - This property sets the control's behavior. The same control may render as different html according to this setting, eg. a hyperlink may be displayed as an actual link or a textbox. It is set according to the Content view's render mode, but can also be overridden with one of the following:
- Default: Sets the render mode according to the Content view's mode.
- Browse: It renders a read-only, presentational markup of the field. This is basically a "public display" mode.
- InlineEdit: It renders the input control in inline mode (see Inline property).
- Edit: Renders the full input control (including Title and Description).
[edit] An example for overriding properties in a Content view:
<sn:ShortText ID="ShortText1" runat="server" FieldName="Name" Title="You can override title here" Description="You can override description here" ReadOnly="true" />
- <sn:ShortText> refers to the ShortText Content field type. It will render as a textbox.
- ID="ShortText1" is the ASP.NET identifier of the given field, so it must be unique in the Content Type Definition.
- runat="server" is compulsory to all ASP.NET server controls. It tells the system to "keep tabs" on the control, enabling the functionality provided by ASP.NET to be used in conjunction with it. This is needed for the Field control to function properly.
- FieldName="..." connects the Field control to the Content field it represents.
- Further properties can be set in xml attributes of the same name. (eg. Title, Description)
