This documentation is archived and is not being maintained.

ToolboxDataAttribute Class

Specifies the default tag generated for a custom control when it is dragged from a toolbox in a tool such as Visual Studio.

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


[Visual Basic]
NotInheritable Public Class ToolboxDataAttribute
   Inherits Attribute
public sealed class ToolboxDataAttribute : Attribute
public __gc __sealed class ToolboxDataAttribute : public Attribute
class ToolboxDataAttribute extends Attribute

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.


By default, the visual designer, of a tool such as Visual.Studio, creates an empty tag. This is a tag representing a control in its default state, when the control is dropped from the toolbox of a visual designer onto the design surface. To specify initial default values, a control can make use of this attribute. You can use this attribute to customize the initial HTML content that is placed in the designer when the control is dragged from the toolbox onto the form.


[Visual Basic, C#, C++] [ ToolboxData("<{0}:MyLabel runat= server Text=

MyLabel><{0}:MyLabel>") ] public class MyLabel : Label {...}

[Visual Basic, C#, C++] In the following example sets several properties specific to MyLabel. All occurrences of {0} are replaced, by the designer, with the tag prefix associated with the MyLabel class.

[Visual Basic] 
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace CustomControls
  <ToolboxData("<{0}:MyLabel Text='MyLabel' BorderColor='Yellow' BackColor='Magenta' BorderWidth = '10'  runat='server'></{0}:MyLabel>")>  _
  Public Class MyLabel
    Inherits Label
    Public Sub New()
      'Your code goes here.
    End Sub 'New
  End Class 'MyLabel
End Namespace 'CustomControls


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CustomControls

  [ ToolboxData("<{0}:MyLabel Text='MyLabel' BorderColor='Yellow' BackColor='Magenta' BorderWidth = '10'  runat='server'></{0}:MyLabel>") ]    
  public class MyLabel : Label 
    public  MyLabel()
      // Your code goes here.


#using <mscorlib.dll>
#using <System.Web.dll>
#using <System.dll>
using namespace System;
using namespace System::Web;
using namespace System::Web::UI;
using namespace System::Web::UI::WebControls;

[ ToolboxData(S"< {0}:MyLabel Text='MyLabel' BorderColor='Yellow' BackColor='Magenta' BorderWidth = '10'  runat='server'></ {0}:MyLabel>") ]
public __gc class MyLabel : public Label 
      // Your code goes here.

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


Namespace: System.Web.UI

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

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

See Also

ToolboxDataAttribute Members | System.Web.UI Namespace | Attribute | Extending Metadata Using Attributes