OnDisplayModeChanged Method

EditorZoneBase.OnDisplayModeChanged Method (Object, WebPartDisplayModeEventArgs)


Raises the DisplayModeChanged event and destroys all EditorPart and child controls in the zone in preparation for a Web page to enter or exit the edit display mode.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

protected override void OnDisplayModeChanged(
	object sender,
	WebPartDisplayModeEventArgs e


Type: System.Object

An Object that raises the DisplayModeChanged event.

Type: System.Web.UI.WebControls.WebParts.WebPartDisplayModeEventArgs

A WebPartDisplayModeEventArgs that contains the event data.

The OnDisplayModeChanged method provides an implementation for the base method in the ToolZone class.

The main purpose of the OnDisplayModeChanged method is to prepare a Web page to enter or exit the edit display mode. The method destroys all controls contained in the zone and then calls the base method, which raises the DisplayModeChanged event in the WebPartManager control.

Notes to Inheritors:

The OnDisplayModeChanged method can be overridden or called programmatically in a custom editor zone control that inherits from the EditorZoneBase class or the EditorZone class.

The following code example demonstrates how to override the OnDisplayModeChanged method in a derived class. For the full code required to run the example, see the Example section of the EditorZoneBase class overview topic.

The custom editor zone derives from the EditorZone class so that it can be used with a zone template in the declarative markup of the Web page. The custom class overrides the OnDisplayModeChanged method, setting the background color of the zone to a specified color, and then calls the base method, which destroys all child and EditorPart controls in preparation for entering or exiting edit display mode.

protected override void OnDisplayModeChanged(object sender, 
  WebPartDisplayModeEventArgs e)
  this.BackColor = Color.LightGray;
  base.OnDisplayModeChanged(sender, e);

When you load the page in a browser, you can select Edit Mode in the drop-down list control to switch to edit mode. You can click the verbs menu (the down arrow) in the title bar of one of the controls, and click Edit to edit the selected control. When the EditorZone control and editing user interface (UI) are visible, you can see that the zone has the background color specified in the code.

.NET Framework
Available since 2.0
Return to top
© 2016 Microsoft