Creating a Composite Control in Asp .Net
A choice towards a composite control is made when there is a need for a group of controls to perform a particular action in sync.
Also it is going to be used in many projects. For example if we want a calculator UI to be made, then it needs a text box, a number of button controls to be grouped together along with the functional code. If this calculator UI and functionality are going to be reused in many projects, then it is wiser to create it as a re-usable control, instead of copy/pasting the code every time. This way, when different web controls are put together as a single control, it makes a composite control.
Adding the Composite Control to the Visual Studio .Net:
A composite control is a Group of some UI of existing controls along with the functional code compiled into a web control library dll . These composite controls need to be used by adding them to the Tool box of Visual Studio .Net. They can be added to the Visual Studio .Net tool box as follows.
- Expand the components group and Right click on the toolbox.
- Click the Add/Remove items.
- Browse to the dll path and ensure that it is checked from the list. It is checked by default when we choose the dll.
- Click Ok.
This will add the composite control to the toolbox. After this, the control can be used normally like any other controls like TextBox, Button etc., Just a drag and drop will do the required actions. When we add this control, VS .Net will add the reference to dll in the background automatically, add the custom server control to the page, add a variable to the code behind file etc.,
Read the next page on Creating the Composite Control using VS .Net.
Attachments
Project Files Composite Controls Sample