WebPropertyEditor Class
Namespace: DevExpress.ExpressApp.Web.Editors
Assembly: DevExpress.ExpressApp.Web.v19.2.dll
Declaration
public abstract class WebPropertyEditor :
PropertyEditor,
ISupportViewEditMode,
IAppearanceFormat,
IAppearanceBase,
ISupportToolTip,
ISupportImmediatePostData
Public MustInherit Class WebPropertyEditor
Inherits PropertyEditor
Implements ISupportViewEditMode,
IAppearanceFormat,
IAppearanceBase,
ISupportToolTip,
ISupportImmediatePostData
Inherit the WebPropertyEditor class to implement a Property Editor using third-party or custom ASP.NET controls. If you use DevExpress controls inherited from ASPxEditBase, use the ASPxPropertyEditor class instead.
In ASP.NET XAF applications, Detail Views can be displayed in two modes - view (read only) and edit (editable). To support these modes, the WebPropertyEditor class introduces the following properties:
Member |
Description |
ViewEditMode |
Specifies the current display mode of the Property Editor's control. |
Editor |
Returns the Property Editor's control used in edit mode. |
InplaceViewModeEditor |
Returns the Property Editor's control used in view mode. |
The WebPropertyEditor class implements the IAppearanceFormat interface to support conditional appearance rules.
Inherit WebPropertyEditor
Specify and Setup the Edit Mode Control
The CreateEditModeControlCore abstract method:
The ReadEditModeValueCore abstract method passes the PropertyValue to the property of the Editor control specifying the displayed content (e.g., Text, Value, etc.).
protected override void ReadEditModeValueCore() {
((ASPxSpinEdit)Editor).Value = PropertyValue;
}
Protected Overrides Sub ReadEditModeValueCore()
CType(Editor, ASPxSpinEdit).Value = PropertyValue
End Sub
The GetControlValueCore abstract method returns the value specified by the WebPropertyEditor.Editor control used in the edit mode.
protected override object GetControlValueCore() {
return ((ASPxSpinEdit)Editor).Value;
}
Protected Overrides Function GetControlValueCore() As Object
Return (CType(Editor, ASPxSpinEdit)).Value
End Function
Customize the View Mode Control (Optionally)
The System.Web.UI.WebControls.Label control is used in the view mode by default. Override these methods to customize the label's string representation or to use another control.
Override The GetPropertyDisplayValue method to customize the string representation of the property value.
protected override string GetPropertyDisplayValue() {
string result = base.GetPropertyDisplayValue();
if (string.IsNullOrEmpty(result)) result = "none";
return result;
}
Protected Overrides Function GetPropertyDisplayValue() As String
Dim result As String = MyBase.GetPropertyDisplayValue()
If String.IsNullOrEmpty(result) Then
result = "none"
End If
Return result
End Function
The CreateViewModeControlCore method instantiates and initializes the control used in the view mode.
protected override WebControl CreateViewModeControlCore() {
Label control = new Label();
// Setup 'control' here.
return control;
}
Protected Overrides Function CreateViewModeControlCore() As WebControl
Dim control As New Label()
' Setup 'control' here.
Return control
End Function
The ReadViewModeValueCore method passes the PropertyValue value to the property of the InplaceViewModeEditor control specifying the displayed content (e.g., Text, Value, etc.).
protected override void ReadViewModeValueCore() {
((Label)InplaceViewModeEditor).Value = PropertyValue;
}
Protected Overrides Sub ReadViewModeValueCore()
CType(InplaceViewModeEditor, Label).Value = PropertyValue
End Sub
Additional Customizations
The SetupControl method instantiates and initializes the control for which the customization code is provided. This method is called when the control is initialized (the Init event occurs).
protected override void SetupControl(WebControl control) {
base.SetupControl(control);
if(ViewEditMode == ViewEditMode.Edit) {
ASPxSpinEdit spinEdit = (ASPxSpinEdit)control;
spinEdit.Width = Unit.Pixel(100);
}
}
Protected Overrides Sub SetupControl(ByVal control As WebControl)
MyBase.SetupControl(control)
If ViewEditMode = ViewEditMode.Edit Then
Dim spinEdit As ASPxSpinEdit = CType(control, ASPxSpinEdit)
spinEdit.Width = Unit.Pixel(100)
End If
End Sub
The BreakLinksToControl(Boolean) method disposes manually allocated resources and unsubscribes from control events.
public override void BreakLinksToControl(bool unwireEventsOnly) {
if(Editor != null) {
((ASPxSpinEdit)Editor).ValueChanged -= EditValueChangedHandler;
}
base.BreakLinksToControl(unwireEventsOnly);
}
Public Overrides Sub BreakLinksToControl(ByVal unwireEventsOnly As Boolean)
If Editor IsNot Nothing Then
RemoveHandler CType(Editor, ASPxSpinEdit).ValueChanged, AddressOf EditValueChangedHandler
End If
MyBase.BreakLinksToControl(unwireEventsOnly)
End Sub
The SetProcessValueChangedScript method registers a script passed to this method parameter to support the IModelOptionsWeb.ConfirmUnsavedChanges mode. The script is executed on the client side after the property value is changed by user. If you use any DevExpress web control, pass the script to the [EditClientSideEvents.ValueChanged]ValueChanged client-side event of the control's ClientSideEvents object.
protected override void SetProcessValueChangedScript(string script) {
if (Editor != null) {
ClientSideEventsHelper.AssignClientHandlerSafe((ASPxSpinEdit)Editor, "ValueChanged", script, Guid.NewGuid().ToString());
}
}
Protected Overrides Sub SetProcessValueChangedScript(script As String)
If Editor IsNot Nothing Then
ClientSideEventsHelper.AssignClientHandlerSafe(CType(Editor, ASPxSpinEdit), "ValueChanged", script, Guid.NewGuid().ToString())
End If
End Sub
If you use a custom third-party control, you should implement a code that provides the script execution when a user updates the editor value.
The SetImmediatePostDataScript method registers a script passed to this method parameter to support the ImmediatePostDataAttribute functionality (it is called only when ImmediatePostData is true). The script should be executed on the client side after the property value is changed by a user. If you use any DevExpress web control, pass the script to the ValueChanged client-side event of the control's ClientSideEvents object.
protected override void SetImmediatePostDataScript(string script) {
ClientSideEventsHelper.AssignClientHandlerSafe((ASPxSpinEdit)Editor, "ValueChanged", script, Guid.NewGuid().ToString());
}
Protected Overrides Sub SetImmediatePostDataScript(ByVal script As String)
ClientSideEventsHelper.AssignClientHandlerSafe(CType(Editor, ASPxSpinEdit), "ValueChanged", script, Guid.NewGuid().ToString())
End Sub
If you use a custom third-party control, you should implement a code that provides the script execution at the moment a user updates the editor value.
The ApplyReadOnly method assigns the AllowEdit value to the Enabled property of the Editor control used in the edit mode. You can apply extra customizations in this method.
protected override void ApplyReadOnly() {
base.ApplyReadOnly();
if (!AllowEdit) {
Editor.ToolTip = "You cannot change this value";
}
else {
Editor.ToolTip = string.Empty;
}
}
Protected Overrides Sub ApplyReadOnly()
MyBase.ApplyReadOnly()
If Not AllowEdit.ResultValue Then
Editor.ToolTip = "You cannot change this value"
Else
Editor.ToolTip = String.Empty
End If
End Sub
Important
- A custom Property Editor that derives from the WebPropertyEditor should not throw exceptions. Exceptions thrown by such a Property Editor interrupt request processing. As a result, the application crashes.
- The WebPropertyEditor's descendant should be public.
- The WebPropertyEditor sets the ID value for the Editor and InplaceViewModeEditor controls. If you use a custom complex control with the inner controls hierarchy, set the ID for each inner control. For details, refer to the How to create controls dynamically article.
To see an example of a Property Editor derived from the WebPropertyEditor class, refer to the How to: Implement a Property Editor Based on Custom Controls (ASP.NET).
See Also