Redigera

Dela via


WebPartZone.GetInitialWebParts Method

Definition

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

protected public:
 override System::Web::UI::WebControls::WebParts::WebPartCollection ^ GetInitialWebParts();
protected internal override System.Web.UI.WebControls.WebParts.WebPartCollection GetInitialWebParts ();
override this.GetInitialWebParts : unit -> System.Web.UI.WebControls.WebParts.WebPartCollection
Protected Friend Overrides Function GetInitialWebParts () As WebPartCollection

Returns

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

Remarks

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.

Note

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.

Applies to

See also