ToolboxDataAttribute Class

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

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

[AttributeUsageAttribute(AttributeTargets.Class)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ToolboxDataAttribute : Attribute

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.

[ ToolboxData("<{0}:MyLabel runat= server Text= 
       MyLabel><{0}:MyLabel>") ]public class MyLabel : Label {...}

In the following code example, the previous code sets several properties specific to MyLabel. All occurrences of {0} are replaced, by the designer, with the tag prefix associated with the MyLabel class.

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.
    } 
  }

}

System.Object
  System.Attribute
    System.Web.UI.ToolboxDataAttribute

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft