Wednesday, March 21, 2007

Advanced User Control Creation Tips


Hi,

Today I am going to discuss about 2 approaches for UserControl creation in ASP.NET

My requirement was to create a control that can hold other controls as child control. In case of User Controls we don't have the option of using a container control like "Panel" as all the User Controls must inherit for the UserControl class.

I will explain a scenario, where it might make sense:
You are building a control which has lots of tables and images etc. So creating a custom control can be really difficult. But the actual requirement is to use this control as like a container control which can hold any other control. This is more of a requirement when you want to use the designer HTML view to create your page.

The approaches are
1. Create a templated control
2. Define a child control container for the User Control

both approaches are easy, but the templated one can be treated as the easiest. But this approach has a problem. The controls that are used inside the Template property cannot be referenced in the main class, that means you need to use the "FindControl" method to access these controls from code behind.

I will explain each approach in subsequent blogs

Labels:

0 Comments:

Post a Comment

<< Home