Introduction
This article describes the use of custom web controls in ASP .NET. Sometimes, when the requirement becomes complex and it’s difficult to build them using the available standard ASP .NET server controls. We can create a web custom control or web user control which will fulfill the requirement.
Web user controls are easy to build, but are less useful in advance scenarios. The web user control is compiled dynamically which makes it difficult to put in toolbox. It is created similar to the web forms and is placed inside the placeholder. In order to share the web user control, one needs to copy the control manually in its application.
Web custom control on the other hand is harder to build, but provide lots of flexibility. The code is compiled so that it can be placed in the toolbox. We can simply drag and drop the control in application and set the properties. It encourages re-usability, without much maintenance. We can install the single copy of web custom control in global assembly cache (gac) which can be shared by different applications.
If your control has a lot of static layout, a user control might make sense. If your control is mostly dynamically generated — for instance rows of a data-bound table, nodes of a tree view, or tabs of a tab control — a custom control would be a better choice.
Web user controls | Web custom controls |
Easier to create | Harder to create |
Limited support for consumers who use a visual design tool | Full visual design tool support for consumers |
A separate copy of the control is required in each application | Only a single copy of the control is required, in the global assembly cache |
Cannot be added to the Toolbox in Visual Studio | Can be added to the Toolbox in Visual Studio |
Good for static layout | Good for dynamic layout |
Reference MSDN
To download complete example of web custom control click here.