title: C# asp.net Button_Click event handler not working
body: <p>I have a webusercontrol with a few controls on it like some labels,a textbox and eventually a button. The purpose of this control is to add it to my main page in a placeholder every time I click on the button on the webusercontrol.</p>
  
  <p>This is the code behind my button on my webcontrol</p>
  
  <pre><code>  protected void btnCriteriaToevoegen_Click(object sender, EventArgs e)
    {
              //New eventhandler == all of the eventhandlers of all the objects who have                      subscribed to the event.
              EventHandler eventhandler = ButtonDoorgaan;
              ButtonOpslaanEvent mijnevent = new ButtonOpslaanEvent();
  
              //Basic variables I will give with my costum event(ButtonOpslaanEvent)
              mijnevent.Naam = txtCriteriumNaam.Text;
              mijnevent.Score = Convert.ToInt16(DdlCriteriumScoreSchaal.SelectedValue);
              int weging = Convert.ToInt16(DdlCriteriumWeging.SelectedValue) - 1;
              mijnevent.Weging = Convert.ToInt16(weging);
  
              //If the eventhandler is not null, for every object that has an eventhandler,   execute it.
              if(eventhandler!=null)
              eventhandler(sender, mijnevent);
          }
  </code></pre>
  
  <p>The eventhandler that need to be executed when the event is fired is defined in my main page like this :</p>
  
  <pre><code>   private void critlijn_ButtonDoorgaan(object sender, EventArgs e)
     {
         ButtonOpslaanEvent eigenevent = (ButtonOpslaanEvent)e;
         IEnumerator&lt;Domein&gt; domeinenumerator = domeinen.GetEnumerator();
         while (domeinenumerator.MoveNext())
         {
             if (domeinenumerator.Current.DomeinNaam.Equals(lijstdomeinitemgeselecteerd))
             {
                 Criterium nieuwcriterium = new Criterium();
                 nieuwcriterium.CriteriumNaam = eigenevent.Naam;
                 nieuwcriterium.CriteriumScore = Convert.ToString(eigenevent.Score);
                 nieuwcriterium.CriteriumWeging = Convert.ToString(eigenevent.Weging);
                 domeinenumerator.Current.Criteriums.Add(nieuwcriterium);
             }
         }
         btnCriteriaToevoegen_Click(sender, e);
     }
  </code></pre>
  
  <p>The btnCriteriaToevoegen_Click event fires and then calls this method(addCriteriaButton()), which will add the button onto the placeholder in my main page:</p>
  
  <pre><code>private void addCriteriaButton()   
  {
      Criterialijn criterialijn = (Criterialijn)LoadControl("~/Criterialijn.ascx");
      //Add eventhandlers to control
      criterialijn.ButtonDoorgaan += new EventHandler(critlijn_ButtonDoorgaan);
      criterialijn.Aangevinkt += new EventHandler(critlijn_Aangevinkt);
      //Every control on the page except this one, not enabled
      IEnumerator&lt;Criterialijn&gt; criterialijnenumerator = criteriacontrols.GetEnumerator();
      while (criterialijnenumerator.MoveNext())
      {
          criterialijnenumerator.Current.Enabled = false;
      }
      //Add it to a list of webusercontrols that are currently on screen
      criteriacontrols.Add(criterialijn);
      criterialijn.Enabled = true;
      //Add to placeholder
      plhCriteria.Controls.Add(criterialijn);
  
  }
  </code></pre>
  
  <p>So when all this is said and done, and I run my program, he adds the control to my placeholder, but when I click on the button, he does not add a new control to my placeholder, and just clears my placeholder for some reason. Normally everything should be fine, but I have tried to see if he actually fires the event when you click on the button, and he does not. I have tried to give you a sample of my code, because the code of the whole page is quite big and that would not help you at all. Any ideas why he is not firing the event of the button?</p>