This documentation is archived and is not being maintained.

ButtonDesigner Class

Used to provide design-time support in a visual designer for the Button Web server control.

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

<SupportsPreviewControlAttribute(True)> _
<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
Public Class ButtonDesigner _
	Inherits ControlDesigner
Dim instance As ButtonDesigner

In a visual designer, when you switch from Source to Design view, the markup source code that describes the Button control is parsed and a design-time version of the control is created on the design surface. When you switch back to Source view, the design-time control is persisted to the markup source code and edited into the markup for the Web page.

This section provides two code examples. The first demonstrates how to extend the ButtonDesigner class. The second demonstrates how to extend the Button class and associate it with the class that is created in the first code example.

The following code example shows how to create a custom designer class that extends the ButtonDesigner class and overrides the GetDesignTimeHtml method. If the BorderStyle property has not been set previously (that is, it has the NotSet field value), a call to the GetDesignTimeHtml method sets it to a blue-dashed border with a width of three pixels, and then displays that border on the design surface. If the BorderStyle property has been set, the existing border property values are displayed.

Typically, the GetDesignTimeHtml calls its base method, ControlDesigner.GetDesignTimeHtml, which calls into the Control.RenderControl method of the associated control to generate the markup.

' Create a class that derives from ButtonDesigner 
' and displays the custom SampleButton control 
' on the design surface. 
Imports System
Imports System.Web.UI.Design
Imports System.Drawing
Imports System.ComponentModel
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls

Namespace Examples.AspNet 

    Public Class SampleButtonDesigner
        Inherits ButtonDesigner

        ' Override the GetDesignTimeHtml method. 
        Public Overrides Function GetDesignTimeHtml() As String 

            Dim sampleButton As SampleButton = CType(Component, SampleButton)
            Dim designTimeHtml As String = Nothing 

            ' Check the control's BorderStyle property 
            ' to conditionally render design-time HTML. 
            If (sampleButton.BorderStyle = BorderStyle.NotSet) Then 

                ' Create variables to hold current property settings. 
                Dim oldBorderStyle As BorderStyle = sampleButton.BorderStyle
                Dim oldBorderWidth As Unit = sampleButton.BorderWidth
                Dim oldBorderColor As Color = sampleButton.BorderColor

                ' Set properties and the design-time HTML. 
                    sampleButton.BorderStyle = BorderStyle.Dashed
                    sampleButton.BorderWidth = Unit.Pixel(3)
                    sampleButton.BorderColor = Color.Blue
                    designTimeHtml = MyBase.GetDesignTimeHtml()

                    ' If an exception occurs, call the GetErrorDesignTimeHtml 
                    ' method. 
                Catch ex As Exception
                    designTimeHtml = GetErrorDesignTimeHtml(ex)

                    ' Return properties to their original settings. 
                    sampleButton.BorderStyle = oldBorderStyle
                    sampleButton.BorderWidth = oldBorderWidth
                    sampleButton.BorderColor = oldBorderColor
                End Try 

                designTimeHtml = MyBase.GetDesignTimeHtml()
            End If 

            Return designTimeHtml

        End Function 

    End Class 
End Namespace

The following code example shows how to use a simple class that extends the Button class and is associated with the SampleButtonDesigner class, created in the preceding example, through the DesignerAttribute object.

<DesignerAttribute( _
    GetType(Examples.AspNet.SampleButtonDesigner))> _
Public Class SampleButton
    Inherits Button
    ' Include code here for a custom  
    ' class that inherits from Button.         
End Class

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0