Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4081938
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:07:29+00:00 2026-05-20T18:07:29+00:00

I have a webusercontrol with a few controls on it like some labels,a textbox

  • 0

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.

This is the code behind my button on my webcontrol

  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);
        }

The eventhandler that need to be executed when the event is fired is defined in my main page like this :

   private void critlijn_ButtonDoorgaan(object sender, EventArgs e)
   {
       ButtonOpslaanEvent eigenevent = (ButtonOpslaanEvent)e;
       IEnumerator<Domein> 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);
   }

The btnCriteriaToevoegen_Click event fires and then calls this method(addCriteriaButton()), which will add the button onto the placeholder in my main page:

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<Criterialijn> 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);

}

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:07:30+00:00Added an answer on May 20, 2026 at 6:07 pm

    So when your button that you dynamically added posts back, a new page instance is created and that button no longer exists (since you only added it on the previous button click), it has not been recreated.

    You must re-create dynamic controls on each postback

    Remeber, a new instance of the Page class is created for each postback, any previously created controls, event handlers will not exists in the new instance unless you explicitly re-create them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This thing is driving me nuts. I have a UserControl that is called WebUserControl.
I have a default.aspx file and 2 user controls. Code for user control 1
I have a UserControl which contains a TextBox and a CustomValidator. I would like
hi i have a problem with the parsecontrol() method Control c = this.ParseControl(<uc1:GroupListControl NickName='HARD'
In a Visual Studio website, I have created a user control. This control is
Have you managed to get Aptana Studio debugging to work? I tried following this,
I want to create a WebUserControl (not a custom control) in asp.NET (C#). I
I have some WebUserControls that take a parameter to determine how they initialize themselves.
I have created a web user control I want to change the iframe' src
<%@ Control Language=C# AutoEventWireup=true CodeFile=WebUserControl.ascx.cs Inherits=WebUserControl %> <script type=text/javascript> function Incrementer() { var txtBox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.