C#•Check the Control Type

Listing 4. The AddControl() method adds a given ASP.NET control into the content PlaceHolder control. Cached controls are treated differently than standard controls, so AddControl() checks the type of control before adding it.

private void AddControl(Control 
   ctl,PlaceHolder content) {
   // Handle cached user controls 
   // (when tracing turned on) 
   // as they cause duplicate IDs when 
   // control itself is added 
   // into control collection

   if (ctl is PartialCachingControl) {
      if 
         (((PartialCachingControl)ctl).CachedControl != null) {
         content.Controls.Add(
            ((PartialCachingControl)ctl).CachedControl);
      }
   } else {
      content.Controls.Add(ctl);
   }
}