Microsoft.SharePoint.WebCon ...


SPCompositeControl Class (Microsoft.SharePoint.WebControls)

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public MustInherit Class SPCompositeControl
    Inherits Control
    Implements INamingContainer
Visual Basic (Usage)
Dim instance As SPCompositeControl
C#
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
public abstract class SPCompositeControl : Control, INamingContainer
Inheritance Hierarchy

System.Object
   System.Web.UI.Control
    Microsoft.SharePoint.WebControls.SPCompositeControl
       Microsoft.SharePoint.WebControls.DateTimeControl
       Microsoft.SharePoint.WebControls.RecurrenceDataControl
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Tags :


Community Content

Adam Buenz - MVP
SPCompositeControl

Description

The abstract Microsoft.SharePoint.WebControls.SPCompositeControl class inherits from the System.Web.UI.Control class for traditional ASP.NET server control support, as well as the System.Web.UI.INamingContainer interface as a marker interface in order to produce unique naming that targets the complete page scope. In order to function, the SPCompositeControl class relies on the INamingContainer interface to handle any of its child controls, since it acts as a container control.

Usage Scenario

The principal usage of SPCompositeControl is as a base class for inheritance for when working with native SharePoint controls that inherit from SPCompositeControl like Microsoft.SharePoint.WebControls.DateTimeControl as a cast type to get access to child control properties, in the context of a DateTimeControl this is how the date value is gathered, within a TextBox, rather than using the SelectedDate property directly on the control.

In the below, the MyClass class is inheriting from the System.Web.UI.WebControls.WebParts.WebPart class. A class level Control typed list collection is provided, which is used later for housing a created SPCompositeControl object. In the overridden CreateChildControls method, the FindControl method is used to create a new DateTimeControl facilitated by safely casting the resulting Control. The previously created DateTimeControl is then used to build a new SPCompositeControl by casting. The resulting SPCompositeObject Controls collection can be indexed following to expose child object properties. Lastly, the control is then added to the class level typed Control collection.

C# Code Example

public class MyClass : WebPart
{
readonly List<Control> collection = new List<Control>();
protected override void CreateChildControls()
{
DateTimeControl dateTime = FindControl("DateTimeControlID") as DateTimeControl;
SPCompositeControl compositeControl = (SPCompositeControl) dateTime;
collection.Add(compositeControl);
}
}

VB.NET Code Example

Public Class [MyClass]
Inherits WebPart
ReadOnly collection As New List(Of Control)()
Protected Overloads Overrides Sub CreateChildControls()
Dim dateTime As DateTimeControl = TryCast(FindControl("DateTimeControlID"), DateTimeControl)
Dim compositeControl As SPCompositeControl = DirectCast(dateTime, SPCompositeControl)
collection.Add(compositeControl)
End Sub
End Class
Tags :

Page view tracker