This documentation is archived and is not being maintained.

WebPartDisplayMode Class

Defines a common set of properties for the several display modes that a Web Parts page can enter.

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

Public MustInherit Class WebPartDisplayMode
Dim instance As WebPartDisplayMode

public abstract class WebPartDisplayMode
public abstract class WebPartDisplayMode
Not applicable.

A Web Parts page can enter several different display modes. In each display mode, certain elements of the Web Parts user interface (UI) are either hidden or displayed, and certain kinds of user modifications to a page are either enabled or disabled. The WebPartManager control contains the implementation for the display modes that are available in the Web Parts control set, and manages the display modes for a page.

The following table lists fields that represent the available display modes.

Display mode



Displays Web Parts controls and UI elements in the normal mode in which end users view a page.


Displays zone UI elements and enables users to drag Web Parts controls to change the layout of a page.


Displays special editing UI elements and enables end users to edit the controls on a page.


Displays special catalog UI elements and enables end users to add and remove page controls.


Displays special connections UI elements and enables end users to connect Web Parts controls.

Notes to Inheritors: Developers can derive from the WebPartDisplayMode class to create custom display modes. To make a custom WebPartDisplayMode available on a Web Parts page, you would also need to derive from the WebPartManager class, and override its CreateDisplayModes method.

The following code examples demonstrate the declarative use of display modes on a Web Parts page. Each of these display modes, as implemented by the Web Parts control set, is derived from the WebPartDisplayMode class.

This code example has four parts:

  • A custom WebPart control.

  • A Web page with a zone to host the custom control.

  • A user control that enables users to change display modes on the Web page.

  • An explanation of how the page works in a browser.

The first part of the example is a custom WebPart control, TextDisplayWebPart. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. For a demonstration of both methods of compiling, see Walkthrough: Developing and Using a Custom Server Control.

Imports System
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

<AspNetHostingPermission(SecurityAction.Demand, _
  Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
  Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class TextDisplayWebPart
    Inherits WebPart
    Private _contentText As String = Nothing
    Private input As TextBox
    Private DisplayContent As Label
    Public Sub New() 
      Me.AllowClose = False
    End Sub
    <Personalizable(), WebBrowsable()>  _
    Public Property ContentText() As String 
            Return _contentText
        End Get
            _contentText = value
        End Set
    End Property
    Protected Overrides Sub CreateChildControls() 
        DisplayContent = New Label()
        DisplayContent.Text = Me.ContentText
        DisplayContent.BackColor = _
        input = New TextBox()
        Dim update As New Button()
        update.Text = "Set Label Content"
        AddHandler update.Click, AddressOf Me.submit_Click
        ChildControlsCreated = True
    End Sub
    Private Sub submit_Click(ByVal sender As Object, _
                             ByVal e As EventArgs) 
        ' Update the label string.
        If input.Text <> String.Empty Then
            Me.ContentText = Page.Server.HtmlEncode(input.Text) + "<br />"
            ' Clear the input textbox.
            input.Text = String.Empty
            DisplayContent.Text = Me.ContentText
        End If
    End Sub
End Class

End Namespace

The second part of the code example is a Web page that references a standard ASP.NET Calendar control within an <asp:webpartzone> element, so that the control is wrapped with a GenericWebPart control and given basic Web Parts functionality at run time. The page also references the TextDisplayWebPart control within an <asp:catalogzone> element, which demonstrates the end user's ability to switch to catalog mode and add controls to the page. The page also includes an <asp:editorzone> element, which enables users to edit the controls contained in the <asp:webpartzone> when the page is in edit mode. Near the top of the page are a register directive for the custom control and another one for the user control.

<%@ page language="VB" %>
<%@ register TagPrefix="uc1" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample" 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">
Sub Button1_Click(Byval sender As Object, _
                  ByVal e As EventArgs)
  WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode
End Sub
<html xmlns="" >
<head id="Head1" runat="server">
  <title>Web Parts Display Modes</title>
  <form id="Form2" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <uc1:DisplayModeMenuVB ID="DisplayModeMenu1" runat="server" />
      runat="server" BackImageUrl="~/MyImage.gif">
            Title="My Calendar" />
    <asp:WebPartZone ID="WebPartZone2" Runat="server">
    <asp:EditorZone ID="editzone1" Runat="server">
          Runat="server" />
          Runat="server" />
    <asp:CatalogZone ID="catalogzone1" Runat="server">
            title = "Text Content WebPart"/>  
    <br />
      text="Catalog Mode"

The third part of the code example is a user control that enables users to switch display modes on a Web page. Save the source code for this control in a file named DisplayModeMenuCS.ascx or DisplayModeMenuVB.ascx (depending on which language you use for the code example), and put it in the same directory as the Web page. For more details about display modes and a description of the source code in this control, see the topic Walkthrough: Changing Display Modes on a Web Parts Page.

<%@ control language="vb" classname="DisplayModeMenuVB"%>
<script runat="server">
  ' Use a field to reference the current WebPartManager.
  Dim _manager As WebPartManager

  Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
    AddHandler Page.InitComplete, AddressOf InitComplete
  End Sub

  Sub InitComplete(ByVal sender As Object, ByVal e As System.EventArgs)
    _manager = WebPartManager.GetCurrentWebPartManager(Page)
    Dim browseModeName As String = WebPartManager.BrowseDisplayMode.Name
    ' Fill the dropdown with the names of supported display modes.
    Dim mode As WebPartDisplayMode
    For Each mode In _manager.SupportedDisplayModes
      Dim modeName As String = mode.Name
      ' Make sure a mode is enabled before adding it.
      If mode.IsEnabled(_manager) Then
        Dim item As New ListItem(modeName, modeName)
      End If
    Next mode
    ' If shared scope is allowed for this user, display the scope-switching
    ' UI and select the appropriate radio button for the current user scope.
    If _manager.Personalization.CanEnterSharedScope Then
      Panel2.Visible = True
      If _manager.Personalization.Scope = PersonalizationScope.User Then
        RadioButton1.Checked = True
        RadioButton2.Checked = True
      End If
    End If
  End Sub

  ' Change the page to the selected display mode.
  Sub DisplayModeDropdown_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    Dim selectedMode As String = DisplayModeDropdown.SelectedValue   
    Dim mode As WebPartDisplayMode = _
    If Not (mode Is Nothing) Then
      _manager.DisplayMode = mode
    End If

  End Sub
  ' Set the selected item equal to the current display mode.
  Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
    Dim items As ListItemCollection = DisplayModeDropdown.Items
    Dim selectedIndex As Integer = _
    DisplayModeDropdown.SelectedIndex = selectedIndex

  End Sub

  ' Reset all of a user's personalization data for the page.
  Protected Sub LinkButton1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
  End Sub

  ' If not in User personalization scope, toggle into it.
  Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    If _manager.Personalization.Scope = PersonalizationScope.Shared Then
    End If

  End Sub
  ' If not in Shared scope, and if user is allowed, toggle the scope.
  Protected Sub RadioButton2_CheckedChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    If _manager.Personalization.CanEnterSharedScope AndAlso _
      _manager.Personalization.Scope = PersonalizationScope.User Then
    End If

  End Sub

  <asp:Panel ID="Panel1" runat="server" 
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server" 
      Text="&nbsp;Display Mode" 
    <asp:DropDownList ID="DisplayModeDropdown" runat="server"  
      OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
    <asp:LinkButton ID="LinkButton1" runat="server"
      Text="Reset User State" 
      ToolTip="Reset the current user's personalization data for the page."
      OnClick="LinkButton1_Click" />
    <asp:Panel ID="Panel2" runat="server" 
      GroupingText="Personalization Scope"
      Visible="false" >
      <asp:RadioButton ID="RadioButton1" runat="server" 
        GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged" />
      <asp:RadioButton ID="RadioButton2" runat="server" 
        OnCheckedChanged="RadioButton2_CheckedChanged" />

When you load the page in a browser, you can use the Display Mode drop-down list control to switch to different display modes. To edit controls, select Edit in the drop-down list control. To edit a specific control, expose its verbs menu by clicking the arrow in the control's title bar, and then clicking Edit in the verbs menu. When a control is in edit mode, the editing controls added to this page enable you to change the edited control's appearance and layout. When you are finished, select Browse in the Display Mode drop-down list control to return the page to a normal view. To add controls to the page, switch to catalog mode. Notice that you can either use the Display Mode drop-down list control, or click the button near the bottom of the page. The inline code for the Button1_Click method demonstrates how to change display modes programmatically. While you are in catalog mode, you can add the custom TextDisplayWebPart control to the page.

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0