WebPartZone.GetInitialWebParts Method

Note: This method is new in the .NET Framework version 2.0.

Overrides the abstract base method and gets the initial set of static WebPart controls contained within the zone's template.

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

protected internal override WebPartCollection GetInitialWebParts ()
protected WebPartCollection GetInitialWebParts ()
protected internal override function GetInitialWebParts () : WebPartCollection

Return Value

A WebPartCollection that contains all the WebPart or other server controls contained in the zone's template.

The GetInitialWebParts method provides an implementation of the abstract base GetInitialWebParts method. The base method provides no implementation, but declares the method so that derived classes can customize how they will get the initial set of controls that belong in a zone, without taking personalization changes into account.

For each server control found in the zone, the CreateWebPart method is called. If a control inherits directly from the WebPart class, it is simply added to the zone's WebParts collection (and to the similar collection of the WebPartManager control). If a control does not inherit directly from WebPart, the Web Parts control set wraps the control with a GenericWebPart object, which enables the control to behave as a WebPart control at run time.

The WebPartZone class implements the base method by returning the set of controls (if any) that are statically declared within a set of <zonetemplate> tags in the markup of a Web Parts page. If a PlaceHolder control is declared in a zone, the child controls of that control are added, rather than the control itself. This implementation allows you to, for example, create a WebPartZone zone in a master page, and then declare individual WebPart or server controls in a content page. If you declare Literal controls in a WebPartZone zone, they are ignored.


The initial collection of controls returned by the GetInitialWebParts method might be different from the actual run-time collection of controls in a zone, after personalization has taken place. For example, suppose you have a Web page with two WebPartZone controls, and the first one contains user control named User1 that is statically declared within the <zonetemplate> tags. If a user loads the page and drags User1 into the second zone, then User1 is still part of the collection that is returned by calling the GetInitialWebParts method for the first zone, because it is declared in that zone. But at run time, when the WebPartManager control loads the personalization data, User1 actually appears in the second zone where the user dragged it.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0