WebPart Class
The WebPart class provides the base class for creating Web Parts. All custom Web Parts must derive from this class. To learn the basic steps for creating a Web Part, see the Creating a Basic Web Part programming task.
System.Object
System.Web.UI.Control
Microsoft.SharePoint.WebPartPages.WebPart
Protected Constructors
The following table shows the constructors of the WebPart class and a brief description of each.
Name | Description |
---|---|
WebPart | Initializes a new instance of the WebPart class. |
Public Methods
The following table shows the public methods of the WebPart class and a brief description of each.
Name | Description |
---|---|
AfterDeserialize | The virtual function that is called after a Web Part's properties are deserialized from the SharePoint database or from a Web Part description file (.dwp). Suggested place for Web Part upgrade code. |
CanRunAt | Returns a ConnectionRunAt enumeration that indicates the appropriate value for where the implementation for connection interface can run. |
CreateWebPartMenu | The virtual function for creating the Web Part menu when a developer wants to modify or override the default menu. |
Dispose | Releases all resources used by the Web Part. |
EnsureInterfaces | Provides notification for a connectable Web Part that it should ensure all its interfaces are registered using the RegisterInterface method. |
GetData | The virtual method that is called by the Web Part infrastructure when the System.Web.UI.Control.PreRender event occurs to allow a Web Part to retrieve data. |
GetDesignTimeFooter | Returns the static HTML for the footer portion of a Web Part frame to a custom designer created by deriving from System.Web.UI.ControlDesigner. |
GetDesignTimeHeader | Returns static HTML for the header portion of a Web Part frame to a custom designer created by deriving from System.Web.UI.ControlDesigner. |
GetInitEventArgs(String) | Returns the Microsoft.SharePoint.WebPartPages.Communication.InitEventArgs object for the name of the interface that is passed in. |
GetRequiresData | The virtual method that is called by the Web Part infrastructure when the System.Web.UI.Control.PreRender event occurs to indicate that a Web Part requires data. |
GetToolParts | Determines which tool parts are displayed in the tool pane of the Web-based Web Part design user interface, and the order in which they are displayed. |
LoadResource(String) | Returns a string that describes the localized Name, Category, and Description property values of the specified resource. |
PartCommunicationConnect(String, Microsoft.SharePoint.WebPartPages.WebPart, String, Microsoft.SharePoint.WebPartPages.Communication.ConnectionRunAt) | Provides a connectable Web Part with the ability to notify other Web Parts that it has a connected interface, where that interface should run, and what that interface is connected to. |
PartCommunicationInit | Provides a connectable Web Part with the ability to run event handlers for any Microsoft.SharePoint.WebPartPages.Communcation "Init" events, such as the CellProviderInit or CellConsumerInit events. |
PartCommunicationMain | Provides a connectable Web Part with a method to run event handlers for any additional events of a connectable Web Part. |
PartCacheInvalidate | Marks all the contents of the Web Part cache as outdated. |
ShouldSerializeAllowMinimize | Returns whether the AllowMimimize property has changed from its default value. |
ShouldSerializeAllowRemove | Returns whether the AllowRemove property has changed from its default value. |
ShouldSerializeAllowZoneChange | Returns whether the AllowZoneChange property has changed from its default value. |
ShouldSerializeConnectionID | Returns whether the ConnectionID property has changed from its default value. |
ShouldSerializeConnections | Returns whether the Connections property has changed from its default value. |
ShouldSerializeDescription | Returns whether the Description property has changed from its default value. |
ShouldSerializeDetailLink | Returns whether the DetailLink property has changed from its default value. |
ShouldSerializeDir | Returns whether the Dir property has changed from its default value. |
ShouldSerializeExportControlledProperties | Returns whether the ExportControlledProperties property has changed from its default value. |
ShouldSerializeFrameState | Returns whether the FrameState property has changed from its default value. |
ShouldSerializeFrameType | Returns whether the FrameType property has changed from its default value. |
ShouldSerializeHeight | Returns whether the Height property has changed from its default value. |
ShouldSerializeHelpLink | Returns whether the HelpLink property has changed from its default value. |
ShouldSerializeIsIncluded | Returns whether the IsIncluded property has changed from its default value. |
ShouldSerializeIsIncludedFilter | Returns whether the IsIncludedFilter property has changed from its default value. |
ShouldSerializeIsVisible | Returns whether the IsVisible property has changed from its default value. |
ShouldSerializeMissingAssembly | Returns whether the MissingAssembly property has changed from its default value. |
ShouldSerializePartImageLarge | Returns whether the PartImageLarge property has changed from its default value. |
ShouldSerializePartImageSmall | Returns whether the PartImageSmall property has changed from its default value. |
ShouldSerializePartOrder | Returns whether the PartOrder property has changed from its default value. |
ShouldSerializeTitle | Returns whether the Title property has changed from its default value. |
ShouldSerializeWidth | Returns whether the Width property has changed from its default value. |
ShouldSerializeZoneID | Returns whether the ZoneID property has changed from its default value. |
Protected Methods
The following table shows the protected methods of the WebPart class and a brief description of each.
Name | Description |
---|---|
AddParsedSubObject(object) | Overrides System.Web.UI.Control.AddParsedSubObject. |
Finalize | The protected implemenation of the System.Object.Finalize method. |
GetCustomBuilder(String) | Provides the ability to associate a dynamic builder with a custom property of a Web Part. |
NotifyWorkItemComplete(System.IAsyncResult) | Indicates that work being performed on an external asynchronous thread that has been registered using the RegisterWorkItem method has completed. |
OnDataBinding(System.EventArgs) | Provides an event handler for the System.Web.UI.Control.DataBinding event that occurs when a Web Part is binding to a data source. |
OnInit(System.EventArgs) | Provides an event handler for the System.Web.UI.Control.Init event that occurs as the Web Part is being instantiated. |
OnLoad(System.EventArgs) | Provides an event handler for the System.Web.UI.Control.Load event indicating that a Web Part is being loaded into the Web Part Page. |
OnPreRender(System.EventArgs) | Provides an event handler for the System.Web.UI.Control.PreRender event that occurs immediately before the Web Part is rendered to its containing Web Part Page. |
OnUnload(System.EventArgs) | Provides an event handler for the System.Web.UI.Control.Unload event, which occurs when the Web Part is being unloaded from memory. |
PartCacheInvalidate(Microsoft.SharePoint.WebPartPages.Storage) | Marks all contents of the specified storage type in the Web Part cache as outdated. |
PartCacheInvalidate(Microsoft.SharePoint.WebPartPages.Storage, String) | Marks the specified cache entries of the specified storage type in the Web Part cache as outdated. |
PartCacheRead(Microsoft.SharePoint.WebPartPages.Storage, String) | Reads and returns a value from the specified location in the specified type of storage in the Web Part cache. |
PartCacheWrite(Microsoft.SharePoint.WebPartPages.Storage, String, object, System.TimeSpan) | Stores the specified value of the specified type of storage in the Web Part cache. |
RegisterInterface(String, String, Int32, Microsoft.SharePoint.WebPartPages.Communication.ConnectionRunAt, object, String, String, String) | Registers an interface from the Microsoft.SharePoint.WebPartPages.Communication Namespace for a connectable Web Part. |
RegisterInterface(String, String, Int32, Microsoft.SharePoint.WebPartPages.Communication.ConnectionRunAt, object, String, String, String, Boolean) | Registers an interface from the Microsoft.SharePoint.WebPartPages.Communication Namespace for a connectable Web Part. |
RegisterWorkItem(System.IAsyncResult) | Keeps track of work being done by an external thread, such as a Web Part that handles its own thread pool. |
RegisterWorkItemCallback(System.Threading.WaitCallback, object) | Queues a Web Part work item to the thread pool, invokes the specified delegate, and specifies an object to be passed to the delegate when serviced from the thread pool. |
ReplaceTokens(String) | Performs token replacement for a string, using the same algorithm used for URL-valued properties. |
Render(System.Web.UI.HtmlTextWriter) | Inherited from System.Web.UI.Control . This method is overridable, but when creating a Web Part you should override the RenderWebPart method instead. |
RenderWebPart(System.Web.UI.HtmlTextWriter) | The virtual method called by the Web Part infrastructure to render the HTML for the body of a Web Part to the client. |
RenderWorkItemTimeout(System.Web.UI.HtmlTextWriter) | Renders HTML in a Web Part when a work item has timed out. |
Public Properties
The following table shows the public properties of the WebPart class, the data type of each property, and a brief description of each.
Name | Data Type | Description |
---|---|---|
AllowMinimize | Boolean | Gets or sets whether the Web Part can be minimized. |
AllowRemove | Boolean | Gets or sets whether the Web Part can be removed from a Web Part Page by controlling whether the IsIncluded property can be set to false |
AllowZoneChange | Boolean | Gets or sets whether the Web Part can be moved to a different zone by controlling whether the ZoneID property can be changed. |
BrowserDesignMode | Boolean | Gets whether a Web Part is in the Web Part Page design mode (changing layout or modifying its properties) in the Web browser. |
Caption | String | Specifies a string that is added following the Title property in the title bar of the Web Part. |
ClientName | String | Gets the unique name of the Web Part used by the client-side Web Parts Page Service Component (WPSC). |
ConnectionID | System.Guid | Gets or sets the Guid that is used internally by the Web Part infrastructure as the unique identifier of a Web Part connection. |
Connections | String | Gets or sets the connection information that is stored with a connected Web Part. |
Description | String | Get or sets a text description that appears when a user rests the mouse pointer on the title of a Web Part in a Web Part Page or in a Web Part library. |
DetailLink | String | Gets or sets a URL to an HTML document that contains supplemental information. |
Dir | Direction | Gets or sets the language direction for a Web Part's text and frame. |
EffectiveFrameType | FrameType | Gets the frame type that is used to render the Web Part frame at run time. |
EffectiveStorage | Storage | Gets whether the instance of the Web Part returned is stored as personal instance or shared instance. |
EffectiveTitle | String | Gets the title of the specified Web Part instance, including any disambiguation information added by the Web Part infrastructure. |
ExportControlledProperties | Boolean | Gets or sets whether a Web Part's properties that are flagged as controlled properties by the Web Part developer can have their values exported in Personal View. |
FrameState | FrameState | Gets or sets the initial state of the Web Part frame, which can be normal (expanded) or minimized. |
FrameType | FrameType | Gets or sets the style of the Web Part frame. |
Height | String | Gets or sets the fixed height for a Web Part on a Web Part Page. |
HelpLink | String | Gets or sets a URL or file system path to a help file in HTML format. |
ID | String | Gets or sets the GUID for the Web Part. |
IsIncluded | Boolean | Gets or sets whether a Web Part, added by another user or the administrator, should be included in a personal view of a Web Part Page. |
IsIncludedFilter | String | Gets or sets the parameters used by the IRuntimeFilter interface to determine if the Web Part will be included on the Web Part page. |
IsVisible | Boolean | Gets or sets whether the part is visible. |
MissingAssembly | String | Gets or sets the message displayed to the user when importing a Web Part, if the assembly for the Web Part is not installed on the target server. |
PartImageLarge | String | Gets or sets the URL of an image file containing a 32 x 32 pixel image, typically used to depict icons. |
PartImageSmall | String | Gets or sets the URL of an image file containing a 16 x 16 pixel image, typically used to depict icons. |
PartOrder | Int32 | Gets or sets the order in which the Web Part appears within a WebPartZone control. |
Permissions | Permissions | Gets which properties of a Web Part can be currently modified. |
Qualifier | String | Gets a unique identifier for a Web Part. |
StorageKey | System.Guid | Gets the unique identifier set by the Web Part infrastructure when a Web Part is added to a zone. |
Title | String | Gets or sets the title that appears in the title bar of a Web Part. |
UseDefaultStyles | Boolean | Gets or sets whether the default font size and style are applied to the Web Part. |
UnknownXmlElements | UnknownXmlElementCollection | Gets an UnknownXmlElementCollection object that contains XML elements from an imported Web Part that were not mapped to a property on the Web Part. |
Width | String | Gets or sets the fixed width for a Web Part. |
ZoneID | String | Gets or sets in which WebPartZone control a Web Part will be rendered. |
Protected Properties
The following table shows the protected properties of the WebPart class, the data type of each property, and a brief description of each.
Name | Data type | Description |
---|---|---|
CacheType | CacheType | Gets the type of caching being used by the Web server. |
ClassResourcePath | String | Gets the base path to Web Part class resources. |
ContainerWidth | String | Gets the WebPartZone.ContainerWidth value set by the page author as a hint to the Web Part of how wide to expect the containing Web Part zone to be. |
OverflowAuto | Boolean | Gets whether to override the default setting for the cascading style sheet (CSS) overflow attribute in the Web Part's rendering. |
SaveProperties | Boolean | Gets or sets whether a Web Part's properties have changed and should be persisted at the end of page rendering. |
SerializeAll | Boolean | Gets whether a retrieved property value should be serialized for use in the client-side WPSC property collection. |
ShouldValidate | Boolean | Gets whether the Web Part infrastructure should perform data validation of Web Part properties before setting them. |
WebPartMenu | Menu | Gets or sets the Web Part menu source that is rendered in the frame of the Web Part. |
WorkItemTimeout | Boolean | Gets whether a work item, such as a data request started with RegisterWorkItemCallback Method has timed out and must be ended. |
Thread Safety
Any public static (Shared in Microsoft Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
Example
The following code example shows a simple Web Part that contains HtmlButton and HtmlInputText controls that allow the user to change the Web Part's Title property. For a step-by-step walkthrough of creating this Web Part, see the Creating a Basic Web Part programming task.
Requirements
Namespace: Microsoft.SharePoint.WebPartPages
Platforms: Microsoft Windows Server 2003
Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)
Security: Code Access Security