How to Create a Custom Control in ASP.NET

If none of the existing ASP.NET server controls meet your requirements, then you can create a custom control by deriving from one of the base control classes.

Adding Custom Control to the Toolbox

1. Create a test Web Forms page. (WebForm1)
2. Using Tools menu, click Add/Remove Toolbox Items.
3. On the .NET Framework Components tab of the Customize ToolBox dialog box, click the Browse button. Find CustomLabel.dll, choose it, and click Open to add CustomControl1 to the list of components in the Customize Toolbox dialog box.
4. Select CustomControl1 in the list of .NET Framework components and click OK. The CustomControl1 is added to the Toolbox.
5. Now you should see an icon for CustomControl1 the on the toolbar.

Add the Custom Control to the Web Forms page

1.Open WebForm1 in Design view and drag the CustomControl1 from the Toolbox to the page.
2. Set the Text property of the control to “Hello World”.

The control’s appearance in Design view is updated to show the written text.