Standard value handlers - Demonstration

In this demonstration you will see value handler for generic ASP.NET webcontrols:

 
Standard Value Handlers
The textbox value handler

The TextBoxValueHandler is the default leaf value handler. In other words, when no value handler is set for the leaf, the TextBoxValueHandler will be used and effectively a textbox will be displayed.

The use of TextBoxValueHandler is pretty straightforward. Any changes to the actual TextBox can be made in the inner content property: TextBox.

Default Leaf
Custom Text Box Leaf
The listbox and dropdownlist value handlers

The ListBoxValueHandler is the value handler for the ListBox control, whereas the DropDownListValueHandler is the value handler for the DropDownList control.

Both value handlers by default create an empty option at the beginning of ListItem's list. This can be turned off by setting the property EmptyOptionFirst to false. Also the text of this option may be changed using the EmptyOptionText option.

To support multiple listbox's multiple selection mode, the ListBoxValueHandler's ValueSeparator property must be set and different than null or empty string. This output value will be a string created from joining the selected values with the separator.

List Box Leaf
Drop Down List Leaf
The RadioButtonList value handler

The RadioButtonListValueHandler also contains the EmptyOptionFirst and EmptyOptionText properties, they work exactly the same as in ListBoxValueHandler and DropDownListValueHandler.

Be careful using the RepeatLayout, RepeatDirection and RepeatColumns properties of the RadioButtonList. They might not compose well with the default MForm layout, so additional work with css is needed.

Radio Button List Leaf


The checkbox value handler

The CheckBoxValueHandler has two vital properties:

  • OnValue property: the returning value of the leaf item if the checkbox is checked on send, the default value is 'on'
  • OffValue property: the returning value of the leaf item if the checkbox is not checked on send, the default value is an empty string
Check Box Leaf
The CheckBoxList value handler

The CheckBoxListValueHandler is similar to the ListBoxValueHandler, as it allows many values at once to be provided. The difference is that the CheckBoxListValueHandler accepts many values by default. Eventually all values from one CheckBoxListValueHandler are taken from and written to only one leaf node, so the array of values is converted to and from string with the use of split and join. This is done with the use of ValueSeparator property.

Because of common inheritance, the CheckBoxListValueHandler also contains properties EmptyOptionFirst and EmptyOptionText, however they are by default set to false.

Again, RepeatLayout, RepeatDirection and RepeatColumns properties of the RadioButtonList might not compose well with the default MForm layout, so additional work with css is needed.

Check Box List Leaf

The FileUpload value handler

The FileUploadValueHandler is unique in its form, because it may only serve providing data. The value of this handler cannot be set, because of security issues (browsers do not allow it).

In order to show the previous value, a CurrentValueLabel property exists. This property can be modified in .aspx as it is an inner property.

File Upload Leaf
XML output

        
Standard value handlers - Description
The value handlers in general

To provide maximum extensibility to the MForm framework, the idea of value handlers has been introduced. Each LeafItem has a specific value handler. Each value handler is associated with a specific value control. The value control of the value handler should be a inner content property of the value handler, so the TextBox value control should be inside TextBoxValueHandler, a ListBox control should be inside ListBoxValueHandler, etc. All standard MForm value handlers which cover the standard form input controls are in the BM.Tools.WebControls.MForm.Controls.ValueHandlers namespace.

The value handler control itself has no representation in the rendered HTML, similarly to the PlaceHolder control.

A value handler is a control that is responsible for communication between the Leaf item and the value control. Particularly, the value handler control sets the value of the value control before the form is displayed and gets the value when the form is back (on the server side) and controls both the value getting/setting when the form is displayed (on the client side).

The server side part of getting/setting the control value is done through the Value property. This property needs to be implemented for every value handler.

The client side part of getting and setting the control value is done through the getControlValue and setControlValue javascript methods.