title: C# Dynamic button not firing click event
body: <p>It reloads the page empty when I click the button. How do I fire click event on button click? I think Page.IsPostBack is the reason it reloads the page empty instead of showing the label.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              if (Page.IsPostBack == false)
              {
                  account account = new account();
                  accountManager accountManager = new accountManager();
                  group group = new group();
                  groupManager groupManager = new groupManager();
                  string emailAddress;
  
                  emailAddress = HttpContext.Current.User.Identity.Name;
                  account = accountManager.getAccInfoByEmailAddress(emailAddress);
                  group = groupManager.getGroupLeader(account.groupNo);
  
                  if (account.groupNo == 0)
                  {
                      divMessage.InnerHtml = "You are not in any group.";
                  }
                  else
                  {
                      try
                      {
                          Button btn = new Button();
                          btn.Text = "Click";
                          btn.Click += new EventHandler(button_Click);
                          form1.Controls.Add(btn);
                      }
                      catch (Exception)
                      {
                          divMessage.InnerHtml = "Unable to retrieve data. Please contact administrator if the problem persists.";
                      }
                  }
              }
          }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>private void button_Click(object sender, EventArgs e)
          {
              Label Label1 = new Label();
              Label1.Text = "rthfg";
              form1.Controls.Add(Label1);
          }
  </code></pre>