InitContentType Class
System.Object
System.Web.UI.Control
Microsoft.SharePoint.WebControls.SPControl
Microsoft.SharePoint.WebControls.TemplateBasedControl
Microsoft.SharePoint.WebControls.FormComponent
Microsoft.SharePoint.WebControls.InitContentType
System.Web.UI.Control
Microsoft.SharePoint.WebControls.SPControl
Microsoft.SharePoint.WebControls.TemplateBasedControl
Microsoft.SharePoint.WebControls.FormComponent
Microsoft.SharePoint.WebControls.InitContentType
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
InitContentType
Description
The Microsoft.SharePoint.WebControls.InitContentType sealed class inherits from the Microsoft.SharePoint.WebControls.FormComponent class which provides the derivation for Windows SharePoint Services form-rendering controls.
InitContentType functions by firstly examining if the current context SPList object has content types enabled through the use of the SPList.ContentTypesEnabled property to toggle visibility. If content types are enabled, a System.Web.UI.WebControls.Label object is created through the use of the System.Web.UI.Control.FindControl method to crawl the rendering template, and Text property will be toggled with the current context SPListItem.ContentType.Name property.
Usage Scenario
The primary usage of the InitContentType class is used within SharePoint rendering templates for item forms, and therefore it is more commonly found within a tag call as:
<SharePoint:InitContentType runat="server"/>
As InitContentType provides SPListItem object information it is often found in combination with other FormComponet derived classes, such as the Microsoft.SharePoint.WebControls.CreatedModifiedInfo class.
Use of the InitContentType object is analogous to any WebControl however due to context calls depends on being within a SPList and SPListItem context so is mainly frequent within forms. In the below, MyClass is deriving from FormComponent. The CreateChildControls method is being overridden, and a new InitContentType object is being created with its ID property being set to something unique. In order to provide the InitContentType.ItemContext property with a context, the current class instance ItemContext is used. Subsequently, this control is added to the current instance control collection.
C# Code Example
public class MyClass : FormComponent
{
protected override void CreateChildControls()
{
InitContentType type = new InitContentType();
type.ID = "My Content Type";
type.ItemContext = ItemContext;
Controls.Add(type);
base.CreateChildControls();
}
}
VB.NET Code Example
Public Class [MyClass]
Inherits FormComponent
Protected Overloads Overrides Sub CreateChildControls()
Dim type As New InitContentType()
type.ID = "My Content Type"
type.ItemContext = ItemContext
Controls.Add(type)
MyBase.CreateChildControls()
End Sub
End Class
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
The Microsoft.SharePoint.WebControls.InitContentType sealed class inherits from the Microsoft.SharePoint.WebControls.FormComponent class which provides the derivation for Windows SharePoint Services form-rendering controls.
InitContentType functions by firstly examining if the current context SPList object has content types enabled through the use of the SPList.ContentTypesEnabled property to toggle visibility. If content types are enabled, a System.Web.UI.WebControls.Label object is created through the use of the System.Web.UI.Control.FindControl method to crawl the rendering template, and Text property will be toggled with the current context SPListItem.ContentType.Name property.
Usage Scenario
The primary usage of the InitContentType class is used within SharePoint rendering templates for item forms, and therefore it is more commonly found within a tag call as:
<SharePoint:InitContentType runat="server"/>
As InitContentType provides SPListItem object information it is often found in combination with other FormComponet derived classes, such as the Microsoft.SharePoint.WebControls.CreatedModifiedInfo class.
Use of the InitContentType object is analogous to any WebControl however due to context calls depends on being within a SPList and SPListItem context so is mainly frequent within forms. In the below, MyClass is deriving from FormComponent. The CreateChildControls method is being overridden, and a new InitContentType object is being created with its ID property being set to something unique. In order to provide the InitContentType.ItemContext property with a context, the current class instance ItemContext is used. Subsequently, this control is added to the current instance control collection.
C# Code Example
public class MyClass : FormComponent
{
protected override void CreateChildControls()
{
InitContentType type = new InitContentType();
type.ID = "My Content Type";
type.ItemContext = ItemContext;
Controls.Add(type);
base.CreateChildControls();
}
}
VB.NET Code Example
Public Class [MyClass]
Inherits FormComponent
Protected Overloads Overrides Sub CreateChildControls()
Dim type As New InitContentType()
type.ID = "My Content Type"
type.ItemContext = ItemContext
Controls.Add(type)
MyBase.CreateChildControls()
End Sub
End Class
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
- 6/3/2010
- Adam Buenz - MVP