EnsureChildControls

written by Ryan Olshan on Sunday, February 12 2006

EnsureChildControls is something useful to keep in mind when creating properties that get/set properties on controls present in, for example, a web form or master page. If the control has not yet been created, you will get a runtime error. What EnsureChildControls does is checks if the child controls have been created, and if not creates them.

public bool MainMenuVisible

{

   get

   {

      EnsureChildControls();

      return MainMenu.Visible;

   }

   set

   {

      EnsureChildControls();

      MainMenu.Visible = value;

   }

}

Kick this post on .NET Kicks

Similar Posts

  1. Nullable Types
  2. 911 Pigeon Alert
  3. Master Pages and User Controls in .NET 2.0

Post a comment