Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ButtonDesigner Class

ButtonDesigner Class

Extends design-time behavior for the Button Web server control.

For a list of all members of this type, see ButtonDesigner Members.

System.Object
   System.ComponentModel.Design.ComponentDesigner
      System.Web.UI.Design.HtmlControlDesigner
         System.Web.UI.Design.ControlDesigner
            System.Web.UI.Design.WebControls.ButtonDesigner

[Visual Basic]
Public Class ButtonDesigner
   Inherits ControlDesigner
[C#]
public class ButtonDesigner : ControlDesigner
[C++]
public __gc class ButtonDesigner : public ControlDesigner
[JScript]
public class ButtonDesigner extends ControlDesigner

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.

Remarks

Unless overridden, the GetDesignTimeHtml method of the ButtonDesigner class sets the Text property of the control to the ID property of the control, if the Text property is empty.

Example

[Visual Basic] The following code example creates a custom designer class, named CustomButtonDesigner, that inherits from the ButtonDesigner class. It overrides the GetDesignTimeHtml method. If the Button.Text property has not been set previously, a call to this method sets it to a string and displays that string on the design surface. If the Text property has been set, the existing property value is displayed.

[Visual Basic] 
' Create a class that derives from ButtonDesigner
' that displays the custom SampleButton control
' on a design surface.
Imports System
Imports System.Design
Imports System.Drawing
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports Examples.AspNet

Namespace Examples.AspNet.Design

' <System.Security.Permissions.SecurityPermission( _
'   System.Security.Permissions.SecurityAction.Demand, _
'    Flags:=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
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.
          Try
              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.
          Finally
              sampleButton.BorderStyle = oldBorderStyle
              sampleButton.BorderWidth = oldBorderWidth
              sampleButton.BorderColor = oldBorderColor
          End Try
          
      Else
          designTimeHtml = MyBase.GetDesignTimeHtml()
      End If
      
      Return designTimeHTML

   End Function   
   
  End Class 
End Namespace

[Visual Basic] The following code example is a simple class, named CustomButton, that inherits from the Button class and is associated with the CustomButtonDesigner class by using the DesignerAttribute class.

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

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI.Design.WebControls

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

Assembly: System.Design (in System.Design.dll)

See Also

ButtonDesigner Members | System.Web.UI.Design.WebControls Namespace | Button

Show:
© 2015 Microsoft