Export (0) Print
Expand All

WebPartDesigner Class

Provides design-time visual support for WebPart controls.

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

'Declaration
<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
Public Class WebPartDesigner _
	Inherits PartDesigner

The WebPartDesigner type exposes the following members.

  NameDescription
Public methodWebPartDesignerInitializes a new instance of the WebPartDesigner class.
Top

  NameDescription
Public propertyActionListsGets the action list collection for the control designer. (Inherited from ControlDesigner.)
Public propertyAllowResizeGets a value indicating whether the control can be resized in the design-time environment. (Inherited from ControlDesigner.)
Public propertyAssociatedComponentsGets the collection of components associated with the component managed by the designer. (Inherited from ComponentDesigner.)
Public propertyAutoFormatsGets the collection of predefined automatic formatting schemes to display in the Auto Format dialog box for the associated control at design time. (Inherited from ControlDesigner.)
Public propertyBehavior Obsolete. Gets or sets the DHTML behavior that is associated with the designer. (Inherited from HtmlControlDesigner.)
Public propertyComponentGets the component this designer is designing. (Inherited from ComponentDesigner.)
Public propertyDataBindingsGets the data bindings collection for the current control. (Inherited from HtmlControlDesigner.)
Protected propertyDataBindingsEnabledGets a value indicating whether data binding is supported by the containing region for the associated control. (Inherited from ControlDesigner.)
Protected propertyDesignerStateGets an object that is used to persist data for the associated control at design time. (Inherited from ControlDesigner.)
Protected propertyDesignTimeElement Obsolete. Gets the design-time object representing the control that is associated with the HtmlControlDesigner object on the design surface. (Inherited from HtmlControlDesigner.)
Protected propertyDesignTimeElementView Obsolete. Gets the view-control object for the control designer. (Inherited from ControlDesigner.)
Public propertyDesignTimeHtmlRequiresLoadComplete Obsolete. Gets a value indicating whether the design host must finish loading before the GetDesignTimeHtml method can be called. (Inherited from ControlDesigner.)
Public propertyExpressionsGets the expression bindings for the current control at design time. (Inherited from HtmlControlDesigner.)
Protected propertyHidePropertiesInTemplateModeInfrastructure. Gets a value indicating whether the properties of the associated control are hidden when the control is in template mode. (Inherited from ControlDesigner.)
Public propertyIDGets or sets the ID string for the control. (Inherited from ControlDesigner.)
Protected propertyInheritanceAttributeGets an attribute that indicates the type of inheritance of the associated component. (Inherited from ComponentDesigner.)
Protected propertyInheritedGets a value indicating whether this component is inherited. (Inherited from ComponentDesigner.)
Protected propertyInTemplateModeGets a value indicating whether the control is in either template viewing or editing mode in the design host. The InTemplateMode property is read-only. (Inherited from ControlDesigner.)
Public propertyIsDirty Obsolete. Gets or sets a value indicating whether the Web server control has been marked as changed. (Inherited from ControlDesigner.)
Protected propertyParentComponentGets the parent component for this designer. (Inherited from ComponentDesigner.)
Public propertyReadOnly Obsolete. Gets or sets a value indicating whether the properties of the control are read-only at design time. (Inherited from ControlDesigner.)
Protected propertyRootDesignerGets the control designer for the Web Forms page that contains the associated control. (Inherited from ControlDesigner.)
Protected propertyShadowPropertiesGets a collection of property values that override user settings. (Inherited from ComponentDesigner.)
Public propertyShouldCodeSerialize Obsolete. Gets or sets a value indicating whether to create a field declaration for the control in the code-behind file for the current design document during serialization. (Inherited from HtmlControlDesigner.)
Protected propertyTagGets an object representing the HTML markup element for the associated control. (Inherited from ControlDesigner.)
Public propertyTemplateGroupsGets a collection of template groups, each containing one or more template definitions. (Inherited from ControlDesigner.)
Protected propertyUsePreviewControlGets a value indicating whether the designer should use a temporary copy rather than the actual control associated with the designer to generate the design-time markup. (Inherited from PartDesigner.)
Public propertyVerbsGets the design-time verbs supported by the component that is associated with the designer. (Inherited from ComponentDesigner.)
Public propertyViewControlGets or sets a Web server control that can be used for previewing the design-time HTML markup. (Inherited from ControlDesigner.)
Public propertyViewControlCreatedGets or sets a value indicating whether a View control has been created for display on the design surface. (Inherited from ControlDesigner.)
Protected propertyVisibleGets a value that indicates whether the control is visible at design time. (Inherited from ControlDesigner.)
Top

  NameDescription
Protected methodCreateChildControlsCreates the child controls of this CompositeControl control. (Inherited from CompositeControlDesigner.)
Protected methodCreateErrorDesignTimeHtml(String)Creates HTML markup to display a specified error message at design time. (Inherited from ControlDesigner.)
Protected methodCreateErrorDesignTimeHtml(String, Exception)Creates the HTML markup to display a specified exception error message at design time. (Inherited from ControlDesigner.)
Protected methodCreatePlaceHolderDesignTimeHtmlProvides a simple rectangular placeholder representation that displays the type and ID of the control. (Inherited from ControlDesigner.)
Protected methodCreatePlaceHolderDesignTimeHtml(String)Provides a simple rectangular placeholder representation that displays the type and ID of the control, and also additional specified instructions or information. (Inherited from ControlDesigner.)
Protected methodCreateViewControlReturns a copy of the associated control for viewing or rendering on the design surface. (Inherited from ControlDesigner.)
Public methodDisposeReleases all resources used by the ComponentDesigner. (Inherited from ComponentDesigner.)
Protected methodDispose(Boolean)Releases the unmanaged resources that are used by the HtmlControlDesigner object and optionally releases the managed resources. (Inherited from HtmlControlDesigner.)
Public methodDoDefaultActionCreates a method signature in the source code file for the default event on the component and navigates the user's cursor to that location. (Inherited from ComponentDesigner.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAttempts to free resources by calling Dispose(false) before the object is reclaimed by garbage collection. (Inherited from ComponentDesigner.)
Public methodGetBoundsRetrieves the coordinates of the rectangle representing the boundaries for the control as displayed on the design surface. (Inherited from ControlDesigner.)
Public methodGetDesignTimeHtmlGets the HTML that is used to represent the control at design time. (Inherited from CompositeControlDesigner.)
Public methodGetDesignTimeHtml(DesignerRegionCollection)Retrieves the HTML markup to display the control and populates the collection with the current control designer regions. (Inherited from ControlDesigner.)
Public methodGetEditableDesignerRegionContentReturns the content for an editable region of the design-time view of the associated control. (Inherited from ControlDesigner.)
Protected methodGetEmptyDesignTimeHtmlRetrieves the HTML markup to represent a Web server control at design time that will have no visual representation at run time. (Inherited from ControlDesigner.)
Protected methodGetErrorDesignTimeHtmlRetrieves the HTML markup that provides information about the specified exception. (Inherited from ControlDesigner.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetPersistenceContentRetrieves the persistable inner HTML markup of the control at design time. (Inherited from ControlDesigner.)
Public methodGetPersistInnerHtml Obsolete. Retrieves the persistable inner HTML markup of the control. (Inherited from ControlDesigner.)
Protected methodGetServiceAttempts to retrieve the specified type of service from the design mode site of the designer's component. (Inherited from ComponentDesigner.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetViewRenderingRetrieves an object that contains the design-time markup for the content and regions of the associated control. (Inherited from ControlDesigner.)
Public methodInitializeBinds the designer to a control and validates that the control is a WebPart control. (Overrides PartDesigner.Initialize(IComponent).)
Public methodInitializeExistingComponentReinitializes an existing component. (Inherited from ComponentDesigner.)
Public methodInitializeNewComponentInitializes a newly created component. (Inherited from ComponentDesigner.)
Public methodInitializeNonDefault Obsolete. Initializes the settings for an imported component that is already initialized to settings other than the defaults. (Inherited from ComponentDesigner.)
Public methodInvalidateInvalidates the whole area of the control that is displayed on the design surface and signals the control designer to redraw the control. (Inherited from ControlDesigner.)
Public methodInvalidate(Rectangle)Invalidates the specified area of the control that is displayed on the design surface and signals the control designer to redraw the control. (Inherited from ControlDesigner.)
Protected methodInvokeGetInheritanceAttributeGets the InheritanceAttribute of the specified ComponentDesigner. (Inherited from ComponentDesigner.)
Public methodIsPropertyBound Obsolete. Retrieves a value indicating whether the specified property on the associated control is data-bound. (Inherited from ControlDesigner.)
Public methodLocalizeUses the provided resource writer to persist the localizable properties of the associated control to a resource in the design host. (Inherited from ControlDesigner.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOnAutoFormatAppliedCalled when a predefined, automatic formatting scheme has been applied to the associated control. (Inherited from ControlDesigner.)
Protected methodOnBehaviorAttached Obsolete. Called when a behavior is associated with the element. (Inherited from HtmlControlDesigner.)
Protected methodOnBehaviorDetaching Obsolete. Called when a behavior disassociates from the element. (Inherited from HtmlControlDesigner.)
Protected methodOnBindingsCollectionChanged Obsolete. Called when the data-binding collection changes. (Inherited from ControlDesigner.)
Protected methodOnClickCalled by the design host when the user clicks the associated control at design time. (Inherited from ControlDesigner.)
Public methodOnComponentChangedCalled when the associated control changes. (Inherited from ControlDesigner.)
Public methodOnComponentChangingRepresents the method that will handle the ComponentChanging event for the associated control. (Inherited from ControlDesigner.)
Protected methodOnControlResize Obsolete. Called when the associated Web server control has been resized in the design host at design time. (Inherited from ControlDesigner.)
Protected methodOnPaintCalled when the control designer draws the associated control on the design surface, if the CustomPaint value is true. (Inherited from ControlDesigner.)
Public methodOnSetComponentDefaults Obsolete. Sets the default properties for the component. (Inherited from ComponentDesigner.)
Public methodOnSetParentProvides a way to perform additional processing when the associated control is attached to a parent control. (Inherited from HtmlControlDesigner.)
Protected methodPostFilterAttributesAllows a designer to change or remove items from the set of attributes that it exposes through a TypeDescriptor. (Inherited from ComponentDesigner.)
Protected methodPostFilterEventsAllows a designer to change or remove items from the set of events that it exposes through a TypeDescriptor. (Inherited from ComponentDesigner.)
Protected methodPostFilterPropertiesAllows a designer to change or remove items from the set of properties that it exposes through a TypeDescriptor. (Inherited from ComponentDesigner.)
Protected methodPreFilterAttributesAllows a designer to add to the set of attributes that it exposes through a TypeDescriptor. (Inherited from ComponentDesigner.)
Protected methodPreFilterEventsSets the list of events that are exposed at design-time for the TypeDescriptor object for the component. (Inherited from HtmlControlDesigner.)
Protected methodPreFilterPropertiesAdds properties to or removes properties from the Properties grid in a design host at design time or provides new design-time properties that might correspond to properties on the associated control. (Inherited from ControlDesigner.)
Protected methodRaiseComponentChangedNotifies the IComponentChangeService that this component has been changed. (Inherited from ComponentDesigner.)
Protected methodRaiseComponentChangingNotifies the IComponentChangeService that this component is about to be changed. (Inherited from ComponentDesigner.)
Public methodRaiseResizeEvent Obsolete. Raises the OnControlResize event. (Inherited from ControlDesigner.)
Public methodRegisterCloneRegisters internal data in a cloned control. (Inherited from ControlDesigner.)
Public methodSetEditableDesignerRegionContentSpecifies the content for an editable region of the control at design time. (Inherited from ControlDesigner.)
Protected methodSetRegionContentSpecifies the content for an editable region in the design-time view of the control. (Inherited from ControlDesigner.)
Protected methodSetViewFlagsAssigns the specified bitwise ViewFlags enumeration to the specified flag value. (Inherited from ControlDesigner.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodUpdateDesignTimeHtmlRefreshes the design-time HTML markup for the associated Web server control by calling the GetDesignTimeHtml method. (Inherited from ControlDesigner.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDesignerFilter.PostFilterAttributesFor a description of this member, see the IDesignerFilter.PostFilterAttributes method. (Inherited from ComponentDesigner.)
Explicit interface implemetationPrivate methodIDesignerFilter.PostFilterEventsFor a description of this member, see the IDesignerFilter.PostFilterEvents method. (Inherited from ComponentDesigner.)
Explicit interface implemetationPrivate methodIDesignerFilter.PostFilterPropertiesFor a description of this member, see the IDesignerFilter.PostFilterProperties method. (Inherited from ComponentDesigner.)
Explicit interface implemetationPrivate methodIDesignerFilter.PreFilterAttributesFor a description of this member, see the IDesignerFilter.PreFilterAttributes method. (Inherited from ComponentDesigner.)
Explicit interface implemetationPrivate methodIDesignerFilter.PreFilterEventsFor a description of this member, see the IDesignerFilter.PreFilterEvents method. (Inherited from ComponentDesigner.)
Explicit interface implemetationPrivate methodIDesignerFilter.PreFilterPropertiesFor a description of this member, see the IDesignerFilter.PreFilterProperties method. (Inherited from ComponentDesigner.)
Explicit interface implemetationPrivate propertyITreeDesigner.ChildrenFor a description of this member, see the ITreeDesigner.Children property. (Inherited from ComponentDesigner.)
Explicit interface implemetationPrivate propertyITreeDesigner.ParentFor a description of this member, see the ITreeDesigner.Parent property. (Inherited from ComponentDesigner.)
Top

The WebPartDesigner class provides the visual representation for WebPart controls at design time. It is derived from the PartDesigner class and adds validation to verify that the associated control is a WebPart control or derived type.

WebPartDesigner inherits a UsePreviewControl property from its parent that is always set to true. This causes the visual design environment to generate a View control to hold a temporary copy of the WebPart on the design surface; this copy is then persisted into markup. If you override the UsePreviewControl property to return false, the visual design environment generates markup directly from the actual WebPart control.

Web Parts designers generally act much like regular control designers; the principal methods for setting design-time appearance derive from the ControlDesigner class. Specifically, you can override the GetDesignTimeHtml method to change the design-time markup associated with the control. You can likewise override the GetErrorDesignTimeHtml and GetEmptyDesignTimeHtml methods to handle errors and empty strings (""), respectively.

The following code example shows the interaction between a WebPart control and its associated WebPartDesigner. The WebPart control contains a Calendar control from which the end user selects his or her birthday, a Button control to submit the selection, and a Label control to display a message on the user's birthday. The WebPartDesigner verifies that the associated control is of the expected type and then customizes the design-time rendering of said control. Note that the visual customizations of the designer are visible only at design time, whereas those of the associated control are visible at both run time and design time.

All the methods overridden in this example derive from the ControlDesigner base class. For other available members and their use, see System.Web.UI.Design.ControlDesigner.

Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.Design.WebControls.WebParts
Imports System.ComponentModel

' <summary> 
' BirthdayPart demonstrates some of the most 
' common overrides of members of the WebPart 
' class. BirthdayPartDesigner shows how to  
' customize the rendering of a custom WebPart 
' control. 
' </summary> 
Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(BirthdayPartDesigner))> _
    Public Class BirthdayPart
        Inherits WebPart
        Private m_birthDate As DateTime
        Private input As Calendar
        Private displayContent As Label

        Public Sub New()
            Me.AllowClose = False 
            Me.Title = "Enter your birthday" 
        End Sub

        <Personalizable(PersonalizationScope.User, True), WebBrowsable()> _
        Public Property BirthDate() As DateTime
            Get 
                Return m_birthDate
            End Get 
            Set(value As DateTime)
                m_birthDate = value
            End Set 
        End Property 

        ' Set the appearance of the control at run time. 
        Protected Overrides Sub CreateChildControls()
            Controls.Clear()
            input = New Calendar()
            Me.Controls.Add(input)
            Dim update As New Button()
            update.Text = "Submit" 
            AddHandler update.Click, New EventHandler(AddressOf Me.submit_Click)
            Me.Controls.Add(update)
            displayContent = New Label()
            displayContent.BackColor = System.Drawing.Color.LightBlue
            Dim br As New Literal()
            br.Text = "<br />" 
            If (Me.m_birthDate.Day = DateTime.Now.Day) AndAlso (Me.m_birthDate.Month = DateTime.Now.Month) Then
                displayContent.Text = "Happy Birthday!" 
                Me.Controls.Add(br)
                Me.Controls.Add(displayContent)
            End If 
        End Sub 

        Private Sub submit_Click(sender As Object, e As EventArgs)
            Me.m_birthDate = input.SelectedDate
        End Sub 
    End Class 

    Public Class BirthdayPartDesigner
        Inherits WebPartDesigner
        Public Overrides Sub Initialize(component As IComponent)
            ' Verify that the associated control is a BirthdayPart. 
            If Not GetType(BirthdayPart).IsInstanceOfType(component) Then 
                Throw New ArgumentException("The specified control is not of type 'BirthdayPart'", "component")
            End If 
            MyBase.Initialize(component)
        End Sub 

        ' Here is where you make customizations 
        ' to design time appearance that will not 
        ' be visible to the end user. 
        Public Overrides Function GetDesignTimeHtml() As String 
            Dim designTimeHtml As String = Nothing 
            Try
                designTimeHtml = MyBase.GetDesignTimeHtml()
                Dim s As String = "<hr /><hr />I just added these lines to the" & " bottom of the control.<hr /><hr /></div>"
                designTimeHtml = designTimeHtml.Replace("</div>", s)
            Catch ex As Exception
                designTimeHtml = GetErrorDesignTimeHtml(ex)
                ' undo any changes in the try block 
            Finally 
            End Try 

            If (designTimeHtml Is Nothing) OrElse (designTimeHtml.Length = 0) Then
                designTimeHtml = GetEmptyDesignTimeHtml()
            End If 
            Return designTimeHtml
        End Function 

        ' This method normally returns a blank string. 
        ' Override to return a meaningful message. 
        Protected Overrides Function GetEmptyDesignTimeHtml() As String 
            Return CreatePlaceHolderDesignTimeHtml("<hr />If the page developer forgot to fill in a " & "required property you could tell them here.<hr />")
        End Function 

        ' Add specific text to the generic error message. 
        Protected Overrides Function GetErrorDesignTimeHtml(e As Exception) As String 
            Dim s As String = "<hr />The control failed to render." 
            Return (s & e.Message & "<hr />")
        End Function 
    End Class 
End Namespace

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft