WebPartZoneBase.WebParts Property

Definition

Gets the collection of Web Parts controls contained within a zone.

C#
[System.ComponentModel.Browsable(false)]
public System.Web.UI.WebControls.WebParts.WebPartCollection WebParts { get; }

Property Value

A WebPartCollection that contains references to all the Web Parts controls in a zone.

Attributes

Examples

The following code example demonstrates the programmatic use of the WebParts property on a WebPartZone control. For the full code example, including the code-behind source file and the .aspx page that contains the zone in this code, see the WebPartZoneBase class overview.

The following code example accesses the WebParts property programmatically and displays a list of the controls contained in WebPartZone1. After you load the page into a browser, click the button labeled List WebPartZone1 WebParts. The IDs and types of the controls are displayed.

C#
protected void Button3_Click(object sender, EventArgs e)
{
  StringBuilder builder = new StringBuilder();
  builder.AppendLine(@"<strong>WebPartZone1 WebPart IDs</strong><br />");
  foreach (WebPart part in WebPartZone1.WebParts)
  {
    builder.AppendLine("ID: " + part.ID 
                        + "; Type:  " + part.GetType() 
                        + @"<br />");
  }
  Label2.Text = builder.ToString();
  Label2.Visible = true;
}

Remarks

The WebParts property can contain references to controls that inherit directly from the WebPart class, as well as other ASP.NET server controls or custom controls within a zone. The Web Parts control set dynamically wraps any control that is not a WebPart control as a GenericWebPart control at run time; this mechanism enables you to use all types of ASP.NET controls as Web Parts controls.

Applies to

Продукт Версії
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also