In my previous article Creating Custom Controls in ASP .Net we have seen the technical approach for creating custom control and in How to make better appearance of your custom control in Visual Studio we have gone through the design aspects of custom control.
Now in this article I will explain how to add your custom control to your Toolbox.
Making Custom Control Class Library Project.
Step 1 – Create a class library project named myControlLib.
Step 2 – Add the following code to a new class named myImage. To download sample code files click here. After downloading add “myImage.cs” and “myImageLogo.bmp” file to your “myControlLib” project. Change the “Build Action” property of “myImageLogo.bmp” to Embedded Resource.
Step 3 – Compile the project.
Note: Above given steps are specific to the code sample that I have created. If you want to rename any of the file or change any other aspects than make sure that you also change the design time attributes of your control.
Example: [Designer ("myControlLib.myImageDesigner,myControlLib")] uses the namespace “myControlLib” that is directly related to the name of the class library project you make.
Adding custom control to toolbox.
Step 1 – Switch over to the web project in which you want to use the control.
Step 2 – In toolbox add your own tab or click on general tab.
Step 3 – Right click in the selected tab area and click Chose Items.
Step 4 – This will open Choose Toolbox Item screen. Click on Browse button and specify the path of dll you created in your myControlLib project.
Step 5 – Click Ok and you’re done. Your Custom control will be added to the toolbox as shown below.