Working on .NET User Controls with Your Code

User controls help you combine different control and form a single control. This single control will encompass the other controls needed for the functionality needed. So by dragging and dropping a single control, you are actually including a lot of different controls that gives a complex functionality.

This helps you to modularize the development of your project since you can combine controls and codes to form a user control. Anything that can be combined and used in different places in your project should be created as a user control for ease of use and for speeding up your development.

By using the LoadControl and the Control.Add method you can add user controls dynamically through code when you are running your program. To add such user controls dynamically you need a placeholder to add.

This placeholder is added to your page during design time to enable you to add the user control during runtime. You can also use the set and the get routine to set the properties for your controls available in the user control.

PlaceHolder_Ctrl.Controls.Add(name_of_UserControl);

The above syntax will add a user control using the Controls.Add method into a PlaceHolder control that was placed in your page during design time.