Export (0) Print
Expand All

CatalogPartChrome Class

Enables developers to override the rendering for only the selected sections of CatalogPart controls in a CatalogZoneBase zone.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class CatalogPartChrome

Chrome refers to the peripheral user interface (UI) elements that frame each Web Parts control or server control contained in a zone. The chrome for a control includes its border, its title bar, and the icons, title text, and verbs menu that appear within the title bar. The appearance of the chrome is set at the zone level, and applies to all the controls in the zone.

The Web Parts control set uses the CatalogPartChrome class to render the chrome for CatalogPart controls. Additionally, this class provides a way for developers to customize the rendering of any CatalogPart controls in a CatalogZoneBase zone. For example, you can override the CreateCatalogPartChromeStyle method to customize some specific style attributes applied to the CatalogZoneBase zone.

The CatalogPartChrome class contains several important methods that are useful when you want to override the rendering of CatalogPart controls. One is the CatalogPartChrome constructor, which you use when you override the CreateCatalogPartChrome method in a custom CatalogZoneBase zone to create an instance of your custom CatalogPartChrome object. Another useful method is the RenderPartContents method, which you can use to control the rendering of the content area of controls in a zone (as opposed to chrome elements such as headers, footers, and title bars). Finally, if you want complete programmatic control over all aspects of rendering the CatalogPart controls, you can override the RenderCatalogPart method.

Notes to Implementers:

If you inherit from the CatalogPartChrome class, you must create a customized CatalogZone zone to return your customized CatalogPartChrome class. The Example section for this class overview demonstrates how to create a customized CatalogZone zone to return a customized CatalogPartChrome class.

The following code example demonstrates how to use the CatalogPartChrome class to override the default rendering of CatalogPart controls in a CatalogZoneBase zone.

The code example has three parts:

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

  • A Web page that hosts all the controls in the example.

  • A class that contains the source code for a custom CatalogPartChrome class and CatalogZoneBase zone.

The first part of the code example is the user control. The source code for the user control comes from another topic. For this code example to work, you need to obtain the .ascx file for the user control from the Walkthrough: Changing Display Modes on a Web Parts Page topic, and place the file in the same folder as the .aspx page in this code example.

The second part of the example is the Web page. Note that there is a Register directive near the top of the file to register the compiled component and a tag prefix. Also note that the page references the custom catalog zone using the element <aspSample:MyCatalogZone>.

<%@ Page Language="C#" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" %>
<%@ Register TagPrefix="uc1" TagName="DisplayModeMenuCS" Src="~/DisplayModeMenuCS.ascx" %>
<!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>Web Parts Page</title>
</head>
<body>
  <h1>Web Parts Demonstration Page</h1>
  <form runat="server" id="form1">
<asp:webpartmanager id="WebPartManager1" runat="server" />
<uc1:DisplayModeMenuCS runat="server" ID="DisplayModeMenu" />
  <br />
  <table cellspacing="0" cellpadding="0" border="0">
    <tr>
      <td valign="top">
    <asp:webpartzone id="SideBarZone" runat="server" 
        headertext="Sidebar">
        <zonetemplate>
        </zonetemplate>
      </asp:webpartzone>
      <aspSample:MyCatalogZone ID="CatalogZone1" runat="server">
      <ZoneTemplate>
          <asp:ImportCatalogPart ID="ImportCatalog" runat="server" />
      </ZoneTemplate>
    </aspSample:MyCatalogZone>
      </td>
      <td valign="top">
    <asp:webpartzone id="MainZone" runat="server" headertext="Main">
         <zonetemplate>
        <asp:label id="contentPart" runat="server" Title="Content">
              <h2>Welcome to My Home Page</h2>
              <p>Use links to visit my favorite sites!</p>
            </asp:label>
         </zonetemplate>
       </asp:webpartzone>
      </td>
      <td valign="top">
      </td>
    </tr>
  </table>
  </form>
</body>
</html>

The third part of the example contains the implementation of the custom catalog part chrome and catalog part zone. MyCatalogZone extends CatalogZone and overrides CreateCatalogPartChrome to return the custom catalog part chrome. MyCatalogPartChrome changes the background color of the catalog control in the CreateCatalogPartChromeStyle method. The background color of the zone is changed in the PerformPreRender method, and text is added to the catalog part in the RenderPartContents method.

namespace Samples.AspNet.CS.Controls
{

    /// <summary> 
    /// Summary description for source 
    /// </summary> 
    public class MyCatalogPartChrome : CatalogPartChrome
    {
        public MyCatalogPartChrome(CatalogZoneBase zone)
            : base(zone)
        {

        }

        protected override Style  CreateCatalogPartChromeStyle(CatalogPart catalogPart, PartChromeType chromeType)
        {
            Style catalogStyle = base.CreateCatalogPartChromeStyle(catalogPart, chromeType);
            catalogStyle.BackColor = Color.Bisque;
            return catalogStyle;
        }

        public override void PerformPreRender()
        {
            Style zoneStyle = new Style();
            zoneStyle.BackColor = Color.Cornsilk;

            Zone.Page.Header.StyleSheet.RegisterStyle(zoneStyle, null);
            Zone.MergeStyle(zoneStyle);
        }

        protected override void  RenderPartContents(HtmlTextWriter writer, CatalogPart catalogPart)
        {
            writer.AddStyleAttribute("color", "red");
            writer.RenderBeginTag("p");
            writer.Write("Apply all changes");
            writer.RenderEndTag();
            catalogPart.RenderControl(writer);
        }

        public override void  RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart)
        {
            base.RenderCatalogPart(writer, catalogPart);
        }
    }

    public class MyCatalogZone : CatalogZone
    {
        protected override CatalogPartChrome  CreateCatalogPartChrome()
        {
            return new MyCatalogPartChrome(this);
        }
    }
}

System.Object
  System.Web.UI.WebControls.WebParts.CatalogPartChrome

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