This documentation is archived and is not being maintained.

PageCatalogPart Class

Provides a catalog that keeps references to all WebPart controls (and other server controls contained in WebPartZoneBase zones) that a user has closed on a single Web Parts page, which enables users to add the closed controls back to the page. This class cannot be inherited.

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

<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class PageCatalogPart _
	Inherits CatalogPart
Dim instance As PageCatalogPart
<asp:PageCatalogPart />

The PageCatalogPart class serves one very specific purpose on a Web Parts page: it acts as a page catalog to maintain any controls previously added to the page that a user has closed, so that the user can add them back to the page. This control is visible only when a Web page is in catalog display mode, a special view that enables users to add and remove controls on the page. Add a PageCatalogPart control to your page if you want to provide users with the flexibility of closing and reopening controls. If your page does not allow users to close controls at all, there is no need to add a PageCatalogPart control to your page.

Only closed controls are added to the page catalog. A closed control has several attributes:

  • It is not visible on the page.

  • It is not rendered on the page.

  • It does not participate in page life-cycle phases.

Closing a control is different from deleting it, which permanently removes it from the page. A user can reopen a closed control instance from a page catalog, but after a user deletes a control, he or she can never recover that specific instance.

The most common and convenient way to add a PageCatalogPart control to a page is by declaring it in page persistence format. As with any declarative CatalogPart control, a PageCatalogPart control must be declared within the proper context of ASP.NET markup elements on a Web page. For a working code example of how to declare a PageCatalogPart control in a Web page, see the Example section of this topic. You must add the following sequence of declarative elements to the page:

  1. An <asp:catalogzone> element must be declared, and a child <zonetemplate> element must be added to it to contain any CatalogPart controls declared in the zone.

  2. An <asp:pagecatalogpart> element must be added as a child of the <zonetemplate> element. There might also be other CatalogPart controls declared as child elements of the <zonetemplate> element, including DeclarativeCatalogPart or ImportCatalogPart controls.

The PageCatalogPart class has only one usable property, the Title property, which overrides the base property so that a default title can be provided for the page catalog if no value is supplied.

The remaining properties for the PageCatalogPart class override the inherited properties, but are not actually used for rendering the control. They are overridden only so that special code attributes can be set on them to hide them from design tools like Microsoft Visual Studio 2005. You should not use these hidden properties, because they have no effect on rendering. The fact that they are hidden from IntelliSense and the Properties pane in Visual Studio helps developers avoid using them by mistake. All these hidden properties are noted as such in their respective Help topics.

The PageCatalogPart class also has several important methods. The GetAvailableWebPartDescriptions method retrieves a WebPartDescription object for each WebPart control in the page catalog, which enables a PageCatalogPart control to display information about each server control without having to create an instance of that control. Another method is the GetWebPart method. This method gets an instance of a particular WebPart control, based on the description passed to the method.


The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

How to: Set the Display Mode of a Web Parts PageBuilding ASP .NET Web Applications
How to: Set the Display Mode of a Web Parts PageBuilding ASP .NET Web Applications

The following code example demonstrates how to use the PageCatalogPart control declaratively on a Web page. This example has four parts:

  • A user control that enables you to change display modes on a Web Parts page.

  • A Web page that contains a CatalogZone control, a PageCatalogPart control, and a DeclarativeCatalogPart control.

  • A source code file that contains two custom WebPart controls.

  • An explanation of how the example works when you load the page in a browser.

The first part of this code example is the user control that enables users to change display modes on a Web page. For details about display modes and a description of the source code in this control, see 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" />

The second part of the code example is the Web page. At the top of the page are two register directives, one for the user control and one for the compiled component that contains the two custom WebPart controls. Notice that the page has a declarative reference to the PageCatalogPart control, nested within the proper hierarchy of declarative elements as described in the Remarks section of this topic. There is also an <asp:declarativecatalogpart> element, which contains references for a standard ASP.NET Calendar control and the two custom WebPart controls, all of which are the controls that users can select from the catalog.

<%@ page language="VB" %>
<%@ register TagPrefix="uc1" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample"  
  Assembly="UserInfoWebPartVB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="" >
  <head id="Head1" runat="server">
      PageCatalogPart Control
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server"  />
      <uc1:DisplayModeMenuVB ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server" >
        <PartTitleStyle BorderWidth="1" 
          Font-Names="Verdana, Arial"
          BackColor="LightBlue" />
          <asp:BulletedList ID="BulletedList1" 
            <asp:ListItem Value="">
            <asp:ListItem Value="">
            <asp:ListItem Value="">
      <asp:CatalogZone ID="CatalogZone1" runat="server">
          <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" 
            Title="My Page Catalog" 
            ChromeType="TitleOnly" />
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1"  
            Description="Contains a user control with Web Parts and 
              an ASP.NET Calendar control.">
              <asp:Calendar ID="Calendar1" runat="server" 
                Title="My Calendar" 
                Description="ASP.NET Calendar control used as a personal calendar." />
                title = "User Information WebPart"
                Description ="Contains custom, editable user information 
                  for display on a page." />
                title = "Text Display WebPart" 
                Description="Contains a label that users can dynamically update." />

The third part of the code example is the source code for the two WebPart controls. 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 walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Web Server Control.

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
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 UserInfoWebPart
    Inherits WebPart
    Private server As HttpServerUtility = HttpContext.Current.Server
    Private _userNickName As String = "Add a nickname." 
    Private _userPetName As String = "Add a pet's name." 
    Private _userSpecialDate As DateTime = DateTime.Now
    Private _userIsCurrent As [Boolean] = True 
    Private _userJobType As JobTypeName = JobTypeName.Unselected

    Public Enum JobTypeName
      Unselected = 0
      Support = 1
      Service = 2
      Professional = 3
      Technical = 4
      Manager = 5
      Executive = 6
    End Enum 

    Private NickNameLabel As Label
    Private PetNameLabel As Label
    Private SpecialDateLabel As Label
    Private IsCurrentCheckBox As CheckBox
    Private JobTypeLabel As Label

    ' Add the Personalizable and WebBrowsable attributes to the   
    ' public properties, so that users can save property values   
    ' and edit them with a PropertyGridEditorPart control.

    <Personalizable(), WebBrowsable(), WebDisplayName("Nickname")> _
    Public Property NickName() As String 
        Dim o As Object = ViewState("NickName")
        If Not (o Is Nothing) Then 
          Return CStr(o)
          Return _userNickName
        End If 
      End Get 
      Set(ByVal value As String)
        _userNickName = server.HtmlEncode(value)
      End Set 
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Pet Name")> _
    Public Property PetName() As String 
        Dim o As Object = ViewState("PetName")
        If Not (o Is Nothing) Then 
          Return CStr(o)
          Return _userPetName
        End If 
      End Get 
      Set(ByVal value As String)
        _userPetName = server.HtmlEncode(value)
      End Set 
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Special Day")> _
    Public Property SpecialDay() As DateTime
        Dim o As Object = ViewState("SpecialDay")
        If Not (o Is Nothing) Then 
          Return CType(o, DateTime)
          Return _userSpecialDate
        End If 
      End Get 

      Set(ByVal value As DateTime)
        _userSpecialDate = value
      End Set 
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Job Type")> _
    Public Property UserJobType() As JobTypeName
        Dim o As Object = ViewState("UserJobType")
        If Not (o Is Nothing) Then 
          Return CType(o, JobTypeName)
          Return _userJobType
        End If 
      End Get 
      Set(ByVal value As JobTypeName)
        _userJobType = CType(value, JobTypeName)
      End Set 
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Is Current")> _
    Public Property IsCurrent() As [Boolean]
        Dim o As Object = ViewState("IsCurrent")
        If Not (o Is Nothing) Then 
          Return CType(o, [Boolean])
          Return _userIsCurrent
        End If 
      End Get 
      Set(ByVal value As [Boolean])
        _userIsCurrent = value
      End Set 
    End Property 

    Protected Overrides Sub CreateChildControls()

      NickNameLabel = New Label()
      NickNameLabel.Text = Me.NickName

      PetNameLabel = New Label()
      PetNameLabel.Text = Me.PetName

      SpecialDateLabel = New Label()
      SpecialDateLabel.Text = Me.SpecialDay.ToShortDateString()

      IsCurrentCheckBox = New CheckBox()
      IsCurrentCheckBox.Checked = Me.IsCurrent

      JobTypeLabel = New Label()
      JobTypeLabel.Text = Me.UserJobType.ToString()

      ChildControlsCreated = True 

    End Sub 

    Private Sub SetControlAttributes(ByVal ctl As WebControl)
      ctl.BackColor = Color.White
      ctl.BorderWidth = 1
      ctl.Width = 200
    End Sub 

    Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
      writer.Write("Pet Name:")
      writer.Write("Special Date:")
      writer.Write("Job Type:")

    End Sub 

  End Class

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class TextDisplayWebPart
    Inherits WebPart
    Private _contentText As String = Nothing 
    Private _fontStyle As String = Nothing 
    Private input As TextBox
    Private DisplayContent As Label
    Private lineBreak As Literal

    <Personalizable(), WebBrowsable()> _
    Public Property ContentText() As String 
        Return _contentText
      End Get 
      Set(ByVal value As String)
        _contentText = value
      End Set 
    End Property 

    Protected Overrides Sub CreateChildControls()
      DisplayContent = New Label()
      DisplayContent.BackColor = Color.LightBlue
      DisplayContent.Text = Me.ContentText

      lineBreak = New Literal()
      lineBreak.Text = "<br />"

      input = New TextBox()
      Dim update As New Button()
      update.Text = "Set Label Content" 
      AddHandler update.Click, AddressOf Me.submit_Click

    End Sub 

    Private Sub submit_Click(ByVal sender As Object, _
                             ByVal e As EventArgs)
      ' Update the label string. 
      If input.Text <> String.Empty Then
        _contentText = input.Text + "<br />"
        input.Text = String.Empty
        DisplayContent.Text = Me.ContentText
      End If 

    End Sub 

  End Class 

End Namespace

When you load the page in a browser, select Catalog Mode in the Display Mode drop-down list control to switch to catalog mode. In catalog mode, you can see the controls that are available to be added to the page. Add one of the controls, then use the Display Mode drop-down list control to return the page to browse mode. Click the verbs menu (the downward arrow) in the title bar of one of the controls, and click Close to close the control. Return the page to catalog mode, and notice that the control you closed now appears in the page catalog, and is available to be added back to the page.

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0