Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
 WebParts Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
WebPartZoneBase.WebParts Property

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

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

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

Visual Basic (Declaration)
Public ReadOnly Property WebParts As WebPartCollection
Visual Basic (Usage)
Dim instance As WebPartZoneBase
Dim value As WebPartCollection

value = instance.WebParts
C#
public WebPartCollection WebParts { get; }
C++
public:
property WebPartCollection^ WebParts {
    WebPartCollection^ get ();
}
J#
/** @property */
public WebPartCollection get_WebParts ()
JScript
public function get WebParts () : WebPartCollection

Property Value

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

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.

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.

Visual Basic
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) 
  Dim builder As New StringBuilder()
  builder.AppendLine("<strong>WebPartZone2 WebPart IDs</strong><br />")
  Dim part As WebPart
  For Each part In  WebPartZone1.WebParts
    builder.AppendLine("ID: " + part.ID + "; Type: " _
                        + part.GetType().ToString() _
                        + "<br />")
  Next part
  Label2.Text = builder.ToString()
  Label2.Visible = True
End Sub 
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;
}

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker