Build a form widget: Implement the form widget class

You must inherit from the FieldControl class and the IFormFieldControl interface.

  1. Add a constructor.
  2. Add the public properties that show up in the dialog for Title, Description, and Example.
  3. Add properties for the controls added in the template.
  4. Using the GetDescriptors method, pass the controls client-side.
  5. Override the following abstract methods and properties:
    • InitializeControls method
      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.
    • TitleControl property
      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 TitleLabel.
    • DescriptionControl property
      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 Read and Write mode. In this example, you are getting the description from a DescriptionLabel.
    • ExampleControl property
      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 ExampleLabel.
    • LayoutTemplateName property
      The 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 null or String.Empty.
    • LayoutTemplatePath property
      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.
    • IFormFieldControl members
      • MetaField
        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.
      • Value
        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.

Was this article helpful?