Export (0) Print
Expand All

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)

'Declaration
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class PageCatalogPart _
	Inherits CatalogPart
'Usage
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.

Accessibility

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.

TopicLocation
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)
        DisplayModeDropdown.Items.Add(item)
      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 
      Else
        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 = _
      _manager.SupportedDisplayModes(selectedMode)
    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 = _
      items.IndexOf(items.FindByText(_manager.DisplayMode.Name))
    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)

    _manager.Personalization.ResetPersonalizationState()

  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
      _manager.Personalization.ToggleScope()
    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
      _manager.Personalization.ToggleScope()
    End If 

  End Sub

</script>
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server" 
      Text="&nbsp;Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" 
      AssociatedControlID="DisplayModeDropdown"/>
    <asp:DropDownList ID="DisplayModeDropdown" runat="server"  
      AutoPostBack="true" 
      Width="120"
      OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
    <asp:LinkButton ID="LinkButton1" runat="server"
      Text="Reset User State" 
      ToolTip="Reset the current user's personalization data for the page."
      Font-Size="8" 
      OnClick="LinkButton1_Click" />
    <asp:Panel ID="Panel2" runat="server" 
      GroupingText="Personalization Scope"
      Font-Bold="true"
      Font-Size="8" 
      Visible="false" >
      <asp:RadioButton ID="RadioButton1" runat="server" 
        Text="User" 
        AutoPostBack="true"
        GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged" />
      <asp:RadioButton ID="RadioButton2" runat="server" 
        Text="Shared" 
        AutoPostBack="true"
        GroupName="Scope" 
        OnCheckedChanged="RadioButton2_CheckedChanged" />
    </asp:Panel>
  </asp:Panel>
</div>

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" 
  TagName="DisplayModeMenuVB" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample"  
  Namespace="Samples.AspNet.VB.Controls" 
  Assembly="UserInfoWebPartVB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>
      PageCatalogPart Control
    </title>
  </head>
  <body>
    <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"
          Font-Size="110%"
          BackColor="LightBlue" />
        <zonetemplate>
          <asp:BulletedList ID="BulletedList1" 
            Runat="server"
            DisplayMode="HyperLink"
            Title="Favorites">
            <asp:ListItem Value="http://msdn.microsoft.com">
              MSDN
            </asp:ListItem>
            <asp:ListItem Value="http://www.asp.net">
              ASP.NET
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
              MSN
            </asp:ListItem>
          </asp:BulletedList>
        </zonetemplate>
      </asp:webpartzone> 
      <asp:CatalogZone ID="CatalogZone1" runat="server">
        <ZoneTemplate>
          <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" 
            Title="My Page Catalog" 
            ChromeType="TitleOnly" />
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1"  
            runat="server" 
            Description="Contains a user control with Web Parts and 
              an ASP.NET Calendar control.">
            <WebPartsTemplate>
              <asp:Calendar ID="Calendar1" runat="server" 
                Title="My Calendar" 
                Description="ASP.NET Calendar control used as a personal calendar." />
              <aspSample:UserInfoWebPart 
                runat="server"   
                id="userinfo1" 
                title = "User Information WebPart"
                Description ="Contains custom, editable user information 
                  for display on a page." />
              <aspSample:TextDisplayWebPart 
                runat="server"   
                id="TextDisplayWebPart1" 
                title = "Text Display WebPart" 
                Description="Contains a label that users can dynamically update." />
            </WebPartsTemplate>              
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
    </form>
  </body>
</html>

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 
      Get 
        Dim o As Object = ViewState("NickName")
        If Not (o Is Nothing) Then 
          Return CStr(o)
        Else 
          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 
      Get 
        Dim o As Object = ViewState("PetName")
        If Not (o Is Nothing) Then 
          Return CStr(o)
        Else 
          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
      Get 
        Dim o As Object = ViewState("SpecialDay")
        If Not (o Is Nothing) Then 
          Return CType(o, DateTime)
        Else 
          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
      Get 
        Dim o As Object = ViewState("UserJobType")
        If Not (o Is Nothing) Then 
          Return CType(o, JobTypeName)
        Else 
          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]
      Get 
        Dim o As Object = ViewState("IsCurrent")
        If Not (o Is Nothing) Then 
          Return CType(o, [Boolean])
        Else 
          Return _userIsCurrent
        End If 
      End Get 
      Set(ByVal value As [Boolean])
        _userIsCurrent = value
      End Set 
    End Property 

    Protected Overrides Sub CreateChildControls()
      Controls.Clear()

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

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

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

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

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

      ChildControlsCreated = True 

    End Sub 

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

    Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
      writer.Write("Nickname:")
      writer.WriteBreak()
      NickNameLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Pet Name:")
      writer.WriteBreak()
      PetNameLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Special Date:")
      writer.WriteBreak()
      SpecialDateLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Job Type:")
      writer.WriteBreak()
      JobTypeLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Current:")
      writer.WriteBreak()
      IsCurrentCheckBox.RenderControl(writer)

    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 
      Get 
        Return _contentText
      End Get 
      Set(ByVal value As String)
        _contentText = value
      End Set 
    End Property 

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

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

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

    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

Community Additions

ADD
Show:
© 2014 Microsoft