Microsoft.SharePoint.WebCon ...


InitContentType Class (Microsoft.SharePoint.WebControls)

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

Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class InitContentType
    Inherits FormComponent
Visual Basic (Usage)
Dim instance As InitContentType
C#
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
public sealed class InitContentType : FormComponent
Inheritance Hierarchy

System.Object
   System.Web.UI.Control
     Microsoft.SharePoint.WebControls.SPControl
       Microsoft.SharePoint.WebControls.TemplateBasedControl
         Microsoft.SharePoint.WebControls.FormComponent
          Microsoft.SharePoint.WebControls.InitContentType
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
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
Tags :

Page view tracker