Build a form widget: Implement the form widget class
You must inherit from the
FieldControl class and the
- Add a constructor.
- Add the public properties that show up in the dialog for
- Add properties for the controls added in the template.
- Using the
GetDescriptors method, pass the controls client-side.
- Override the following abstract methods and properties:
As with all Sitefinity CMS widgets that inherit from
SimpleView, you must override the
InitializeControls method. You can think of this as an alternative of the
CreateChildControls method in custom ASP.NET controls.
In this example, you are setting some labels and textbox values in the first method and using a helper method to get the current Sitefinity CMS user.
The property returns a control from the template of your widget control, which displays the title. When in
Write mode, all field controls have a title, displayed in the backend form. In this example, you are getting the title of the widget from the
DescriptionControl must return a control from the template, which displays the description of your custom field control. You can have a different description in
Write mode. In this example, you are getting the description from a
The property returns a control from the template, which displays an example of the value that your field control expects from the user. In this example, you are getting the example from a
- LayoutTemplateName property
LayoutTemplateName property is not specific to field controls, but to all widgets that inherit from
SimpleView. This property is obsolete. You must use the
LayoutTemplatePath instead. In this example, you can return
Although it is not abstract, we recommend that you override the
LayoutTemplatePath property. You must return a path to the template used by your widget. You can either use a path to an embedded resource or an external file. For more information, see VirtualPathProvider.
The property is used to persist data from the control to the database when form is submitted.
You can use complex properties with
TypeConverter attribute that serializes to a primitive type.
The method is used to get and set the value of the widget.
In this example, you are getting and setting the value from a textbox control.
EXAMPLE: For more information about the contents of the file, see
FormWidget.cs in Sitefinity documentation-samples on GitHub.