System.Web.UI.WebControls.WebParts.WebPart Class

Serves as the base class for custom ASP.NET Web Parts controls, adding to the base System.Web.UI.WebControls.WebParts.Part class features some additional user interface (UI) properties, the ability to create connections, and personalization behavior.

See Also: WebPart Members

Syntax

public abstract class WebPart : Part, IWebActionable, IWebPart

Remarks

When you create controls with Web Parts functionality, you have two basic options. You can create custom controls that derive from the System.Web.UI.WebControls.WebParts.WebPart class, or you can create or use other server controls. Existing ASP.NET controls, custom server controls, and user controls can all be given full Web Parts functionality by declaring them within (or adding them programmatically to) a System.Web.UI.WebControls.WebParts.WebPartZone zone control, with the result that they will be wrapped with System.Web.UI.WebControls.WebParts.GenericWebPart objects at run time and treated as true System.Web.UI.WebControls.WebParts.WebPart controls. For details, see the documentation for the System.Web.UI.WebControls.WebParts.GenericWebPart class. For speed of development and maximum reuse of code, using existing server controls can be a good option. For maximum programmatic control over the behavior and Web Parts functionality of controls, creating a custom control that inherits from the System.Web.UI.WebControls.WebParts.WebPart class is often the best option.

The abstract System.Web.UI.WebControls.WebParts.WebPart class inherits from the base System.Web.UI.WebControls.WebParts.Part control and provides the basic elements for all System.Web.UI.WebControls.WebParts.WebPart controls. The class includes a common set of properties that affect the appearance of the UI. The WebPart.AllowClose, WebPart.AllowConnect, WebPart.AllowEdit, WebPart.AllowHide, WebPart.AllowMinimize, and WebPart.AllowZoneChange properties each specify whether the user of a Web application is permitted to interact with the part control in the way indicated by the given property name. The WebPart.CatalogIconImageUrl, WebPart.ChromeState, WebPart.ChromeType, WebPart.Description, WebPart.Height, WebPart.HelpUrl, WebPart.Hidden, WebPart.Title, WebPart.TitleIconImageUrl, WebPart.TitleUrl, and WebPart.Width properties determine the size, visibility, appearance, and supporting content (such as a title and a description) for a System.Web.UI.WebControls.WebParts.WebPart control.

The relationship of a System.Web.UI.WebControls.WebParts.WebPart control to its context within the Web Parts control set is determined by properties such as WebPart.WebPartManager, which holds a reference to the control's associated System.Web.UI.WebControls.WebParts.WebPartManager object, and WebPart.Zone, which references the System.Web.UI.WebControls.WebParts.WebZone that contains the control. There can be only one System.Web.UI.WebControls.WebParts.WebPartManager control per page, and each instance of a System.Web.UI.WebControls.WebParts.WebPart control can reside within only one System.Web.UI.WebControls.WebParts.WebZone at a time.

Note:

A System.Web.UI.WebControls.WebParts.WebPart control can be placed outside of a zone on a Web page, but in this case it functions as a normal server control and loses nearly all Web Parts functionality.

Several other important properties affect unique features of System.Web.UI.WebControls.WebParts.WebPart controls. The WebPart.AuthorizationFilter property allows developers to set an arbitrary string that can be used as a filter at run time to determine whether a control is added to the page. Used together with a feature such as role management, the WebPart.AuthorizationFilter property provides a useful mechanism for creating views based on defined user roles. The WebPart.ExportMode property indicates whether, during an export, all the available property data on a control is exported, or only the non-sensitive data. This allows developers to distinguish between data that is sensitive and data that is not, for security purposes. The WebPart.WebBrowsableObject property returns a reference to an instance of a System.Web.UI.WebControls.WebParts.WebPart control, so that an System.Web.UI.WebControls.WebParts.EditorPart control can edit it when the page is in edit mode. Finally, there are several properties that indicate the status of the control relative to the rest of the page. The WebPart.IsClosed property indicates whether a control is closed (and thus added to a System.Web.UI.WebControls.WebParts.PageCatalogPart object), or if it is open and available on the page. The WebPart.IsShared property indicates whether a control is a shared control (versus a user-specific control), meaning that it is visible to all users of a Web page. The WebPart.IsStandalone property indicates whether a control is currently contained in a System.Web.UI.WebControls.WebParts.WebPartZoneBase-derived zone (such as System.Web.UI.WebControls.WebParts.WebPartZone). A value of false indicates the control is inside a zone and thus has full Web Parts functionality. The WebPart.IsStatic property indicates whether a control is static or dynamic. A static control is declared in the markup of a Web page, whereas a dynamic control is added programmatically.

The System.Web.UI.WebControls.WebParts.WebPart class also provides several methods that determine what happens at various points in the control's life cycle. For example, the WebPart.OnConnectModeChanged(EventArgs) and WebPart.OnEditModeChanged(EventArgs) methods can both be overridden in a derived class to provide programmatic control over the rendering of a control's contents during the event that corresponds to each method's name.

Classes that derive from System.Web.UI.WebControls.WebParts.WebPart can add System.Web.UI.WebControls.WebParts.WebPartVerb objects to the WebPart.Verbs collection. The verbs are rendered in a verbs menu, which appears in the title bar of a System.Web.UI.WebControls.WebParts.WebPart control. System.Web.UI.WebControls.WebParts.WebPartVerb objects provide simple UI elements for common user actions such as hiding or minimizing the control or displaying Help.

The WebPart.CreateEditorParts method creates a collection of any custom System.Web.UI.WebControls.WebParts.EditorPart controls that are associated with a System.Web.UI.WebControls.WebParts.WebPart control. Developers can override this method so that it creates custom controls designed specifically to edit their System.Web.UI.WebControls.WebParts.WebPart control. The method is called when a user clicks the edit verb on a System.Web.UI.WebControls.WebParts.WebPart control.

Requirements

Namespace: System.Web.UI.WebControls.WebParts
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0