title: Problem with programmatically generated controls
body: <pre><code>public partial class Default2 : System.Web.UI.Page
  {
  
      protected void Page_Load(object sender, EventArgs e)
      {
          GenerateButtons generate = new GenerateButtons();
          generate.Generate5Controls(PlaceHolder1);
  
      }
  
  
  }
  
  
  class GenerateButtons
  {
      PlaceHolder placeHolder;
     public  void Generate5Controls(PlaceHolder placeH)
      {
          placeHolder = placeH;
          for (int i = 0; i &lt; 5; i++)
          {
              Button newBtn = new Button();
              newBtn.Click += btn_Click;
              newBtn.Text = "PageLoadButton Created. Number: "+i;
              placeHolder.Controls.Add(newBtn);
          }
      }
      public void btn_Click(object sender, EventArgs e)
      {
          Button newBTN = new Button();
          newBTN.Text = "A New Button was added by the button event btn_click";
          newBTN.Click += btn2_Click;
          placeHolder.Controls.Add(newBTN);
  
      }
      public void btn2_Click(object sender, EventArgs e)
      {
          Button newBTN = new Button();
          newBTN.Text = "A New Button was added by the button event btn2_click";
          placeHolder.Controls.Add(newBTN);
      }
  }
  </code></pre>
  
  <p>I want the events btn_click &amp; btn2_click to fire every post back.. When i click the button that was programmatically created it disappears after each postback and its event doesnt fire (btn2_click). I know i could generate the button at the postback.. But I dont want to do that!! I want to know how I could update the state of the placeholder... so that the only button will appear and the 5 buttons generated in  Generate5Controls(PlaceHolder placeH) to disappear.</p>
  
  <p>I could use a bool Viewstate to prevent this    generate.Generate5Controls(PlaceHolder1); from being execute.. </p>
  
  <p>But the question is how do I make the programmatically generated button to appear!?</p>