UserControlContainerDesigner Class
System.Object
System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
Microsoft.SharePoint.WebControls.UserControlContainerDesigner
System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
Microsoft.SharePoint.WebControls.UserControlContainerDesigner
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
UserControlContainerDesigner
Description
The Microsoft.SharePoint.WebControls.UserControlContainerDesigner class inherits from the System.Web.UI.Design.ControlDesigner class which is responsible for managing the design-mode behavior of a server control. The ControlDesigner class, at a very high level, provides the structure for building control designers and contains the required interfaces to support those behaviors.
In order to manage designer transactions, within the overridden Initialize method, the System.ComponentModel.Design.IDesignerHost interface is used as the house for System.Web.UI.UserControl loaded out of the controltemplates directory in the SharePoint 12 hive. The IDesignerHost object is then safely casted to a System.Web.UI.Design.ControlDesigner subsequent to a IDesignerHost.GetDesigner call consuming the previous UserControl.
Following, the ControlDesigner.GetViewRendering() method is called, and its Content string property is exposed getting the design-time HTML markup.
Usage Scenario
The primary usage of the UserControlContainerDesigner is when working with the shipped SharePoint user controls within a design time environment. The class, as described, is hardcoded to the ControlTemplates directory so can be restrictive for custom development. However, when deploying custom UserControls, UserControlContainerDesigner can be used for custom controls for loading of the UserControl within SharePoint Designer. This technique involve using UserControlContainerDesigner as a System.ComponentModel.Designer class attribute type, combined with inheritance with Microsoft.SharePoint.WebControls.IDesignerEventAccessor interface the UserControl is forced into implementing the call to OnLoad and OnPreRender.
In the below example, MyClass is inheriting from UserControl and IDesignEventAccessor, implementing the respective members of IDesignEventAccessor with calls to the UserControl OnLoad and OnPreRender. The MyClassSystem.ComponentModel.Designer class attribute type is set to UserControlContainerDesigner.
C# Code Example
[Designer(typeof(UserControlContainerDesigner))]
public class MyClass : UserControl, IDesignerEventAccessor
{
public void OnDesignerLoad(EventArgs e)
{
OnLoad(e);
}
public void OnDesignerPreRender(EventArgs e)
{
OnPreRender(e);
}
}
VB.NET Code Example
<Designer(GetType(UserControlContainerDesigner))> _
Public Class [MyClass]
Inherits UserControl
Implements IDesignerEventAccessor
Public Sub OnDesignerLoad(ByVal e As EventArgs)
OnLoad(e)
End Sub
Public Sub OnDesignerPreRender(ByVal e As EventArgs)
OnPreRender(e)
End Sub
End Class
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
The Microsoft.SharePoint.WebControls.UserControlContainerDesigner class inherits from the System.Web.UI.Design.ControlDesigner class which is responsible for managing the design-mode behavior of a server control. The ControlDesigner class, at a very high level, provides the structure for building control designers and contains the required interfaces to support those behaviors.
In order to manage designer transactions, within the overridden Initialize method, the System.ComponentModel.Design.IDesignerHost interface is used as the house for System.Web.UI.UserControl loaded out of the controltemplates directory in the SharePoint 12 hive. The IDesignerHost object is then safely casted to a System.Web.UI.Design.ControlDesigner subsequent to a IDesignerHost.GetDesigner call consuming the previous UserControl.
Following, the ControlDesigner.GetViewRendering() method is called, and its Content string property is exposed getting the design-time HTML markup.
Usage Scenario
The primary usage of the UserControlContainerDesigner is when working with the shipped SharePoint user controls within a design time environment. The class, as described, is hardcoded to the ControlTemplates directory so can be restrictive for custom development. However, when deploying custom UserControls, UserControlContainerDesigner can be used for custom controls for loading of the UserControl within SharePoint Designer. This technique involve using UserControlContainerDesigner as a System.ComponentModel.Designer class attribute type, combined with inheritance with Microsoft.SharePoint.WebControls.IDesignerEventAccessor interface the UserControl is forced into implementing the call to OnLoad and OnPreRender.
In the below example, MyClass is inheriting from UserControl and IDesignEventAccessor, implementing the respective members of IDesignEventAccessor with calls to the UserControl OnLoad and OnPreRender. The MyClassSystem.ComponentModel.Designer class attribute type is set to UserControlContainerDesigner.
C# Code Example
[Designer(typeof(UserControlContainerDesigner))]
public class MyClass : UserControl, IDesignerEventAccessor
{
public void OnDesignerLoad(EventArgs e)
{
OnLoad(e);
}
public void OnDesignerPreRender(EventArgs e)
{
OnPreRender(e);
}
}
VB.NET Code Example
<Designer(GetType(UserControlContainerDesigner))> _
Public Class [MyClass]
Inherits UserControl
Implements IDesignerEventAccessor
Public Sub OnDesignerLoad(ByVal e As EventArgs)
OnLoad(e)
End Sub
Public Sub OnDesignerPreRender(ByVal e As EventArgs)
OnPreRender(e)
End Sub
End Class
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
- 6/3/2010
- Adam Buenz - MVP