Skip to main content
A newer version of this page is available.
All docs
V18.2

How to: Display a Detail View Directly in Edit Mode in ASP.NET Applications

  • 2 minutes to read

In ASP.NET Web and Mobile applications, when clicking a record in a List View, a Detail View is displayed in view mode. However, the SwitchToEditMode Action is available, and you can use it to reload the Detail View in edit mode. This is the default behavior. In individual scenarios, you may need to invoke a Detail View directly in edit mode. This topic demonstrates how to omit the display in view mode for a particular object type.

To set a Detail View’s display mode, use the DetailView.ViewEditMode property. To change this property value, implement a View Controller and override the OnActivated method.

using DevExpress.ExpressApp.Editors;
//...
public class SwitchToEditModeModificationsController : ViewController<DetailView> {
    protected override void OnActivated() {
        base.OnActivated();
        if (View.ViewEditMode == ViewEditMode.View) {
            View.ViewEditMode = ViewEditMode.Edit;
            ObjectSpace.SetModified(null);
        }
    }
}

To accomplish the implemented code when the current View represents an object of a particular type, set the ViewController.TargetObjectType property to this type in the View Controller’s constructor. As an example, assume that the Controller is intended for Person type objects.

public SwitchToEditModeModificationsController() {
    TargetObjectType = typeof(Person);
}

If you now run the application, you will see that the Person Detail View is always displayed in edit mode.

Note

The View Controller demonstrated in this topic should be implemented in an ASP.NET or Mobile module. In Windows Forms applications, Detail Views are always editable.

See Also