How to Implement Toolbox Support in .NET?

Toolbox support is one of the design time support provided by Visual Studio .NET for server controls. If you have a custom web control or server controls that has to be accessed across many applications, then that control has to be installed and implemented in Visual Studio Toolbox Support.

Once the control is available in your toolbox then it can be dragged and dropped into your web form. Examples for custom web control include Calendar that is specifically designed by you or a button managing image uploads. This article explains you how to implement this toolbox support for the custom web control in your application.

Add Custom Control to the Toolbox: There are two different ways of adding custom control to the toolbox.

1) In design view, choose the web forms tab of VS.NET toolbox. Right-click and choose “Add/Remove Items”. Choose “.NET Framework Components” tab and click on browse. Select the location of the control assembly and click “’OK”.

2) You would have created a library project in Visual Studio for defining your custom control. In the corresponding View menu, click on Toolbox. Right-click on that and select “Choose Items”. In the corresponding dialog box that appears, choose “.NET Framework Components” tab and click on browse. Locate the dll for the control you have built. Select the checkbox of your specific control and click on “OK”.

Now the custom control will appear in the toolbox. You can customize the icon that is displayed for the control in the toolbox. For that, create a BMP file of 16X16 pixels in the same name as that of your control’s class. Use the command “Add Existing Item” to add this BMP file to your project and then set the “Build Action” as “Embedded Resource” in the property browser. After compilation, your customized icon will be reflected against your control in the tool box.

TagPrefix and Namespace: Double-click on the control icon or drag and drop the icon into your web form to access that control in your page. When you drag and drop a control, tagprefix and namespace will be assigned to it automatically. If the tagprefix is not specified, then VS.NET generates the tagprefix which starts with cc. You will generally set attributes at property level. In addition, you can also set attributes either at class level or at assembly level.

Here is an example code of a control which sets attributes at assembly level:

[assembly: TagPrefix(“testNamespace”,”testTagPrefix”)]

namespace testNamespace
{
[
ToolboxData("<{0}:test Text=”Testing Toolbox” runat=server></{0}:test>")
]

public class test: System.Web.UI.Webcontrols.Webcontrol
{
//your specific code
protected override void Render(HTMLTextWriter textWriter)
{
//your specific code
}
}
}

TagPrefix and the ToolboxData are the two attributes which ensure presence of the control in the toolbox. TagPrefix mentions the prefix that is used to refer the control and ToolboxData contains the default tag that is generated when the control is dragged and dropped from the toolbox.

This is the definition and implementation code of the control you have created. The placeholders {0} will be substituted with the actual TagPrefix value when your page is using the control from the toolbox. You will compile this control and save it as a “.dll” file which will be located when the control has to be displayed in the toolbox, in the earlier step.

| Understanding ASP.NET Page Lifecycle | Exploring Different Stages of Memory Management in .NET | How to Implement Forms Authentication Provider in .NET | How to Implement Toolbox Support in .NET? | How to Read and Write Files with Streams in ASP.NET? | How to Use a Custom Web Control in VS.NET? | Implementing .NET Passport Authentication in Web Applications Using Passport Authentication Provider | Using Atlas Architecture in ASP.NET |

 


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.