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 8090849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:51:36+00:00 2026-06-05T19:51:36+00:00

I got a query regarding adding dynamic buttons with dynamic onclick events on a

  • 0

I got a query regarding adding dynamic buttons with dynamic onclick events on a set of updatepanels.

I’ve simplified the scenario as the code I have so far is way too long and tied up..I’ve created a test page with 3 update panels.

In terms of the actual page the first updatepanel will be for the filters which will in turn update the second update panel. 2nd update panel will consist of all the results, depending on filters..this will be a table of buttons.

On the click of any of these buttons on the second update panel, depending on the ID of the button the results will be generated in the last update panel.

The problem I’m facing is tieing in the button click event when the buttons are created.
When I create the button from the onclick from the first update panel, it adds it to the placeholder but the click event does not fire at all.

Here is some code from my testing page.

test.aspx

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>

</asp:UpdatePanel>


<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="False" 
    UpdateMode="Conditional">
<ContentTemplate>

<asp:PlaceHolder id="ph2" runat="server"></asp:PlaceHolder>
</ContentTemplate>

</asp:UpdatePanel>


<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">

<ContentTemplate>
<asp:PlaceHolder id="ph3" runat="server"></asp:PlaceHolder>
</ContentTemplate>

</asp:UpdatePanel>

Codebehind:

    public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Button up2button = new Button();
        up2button.ID = "up2button";
        ph2.Controls.Add(up2button);
        up2button.Click += new EventHandler(up2button_Click); // Not being registered?

        AsyncPostBackTrigger trigger1 = new AsyncPostBackTrigger();
        trigger1.ControlID = "up2button";
        trigger1.EventName = "Click";
        UpdatePanel2.Triggers.Add(trigger1);

        ScriptManager1.RegisterAsyncPostBackControl(up2button);

        UpdatePanel2.Update();

    }

    protected void up2button_Click(object sender, EventArgs e) { //and not being fired
        Button up3button = new Button();
        up3button.ID = "up3button";
        up3button.Click += new EventHandler(up3button_click);
        ph3.Controls.Add(up3button);


        AsyncPostBackTrigger trigger1 = new AsyncPostBackTrigger();
        trigger1.ControlID = "up3button";
        trigger1.EventName = "Click";
        UpdatePanel3.Triggers.Add(trigger1);
        UpdatePanel3.Update();
    }

    protected void up3button_click(object sender, EventArgs e) {


    }
}

Thankyou for your time.

  • 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-06-05T19:51:38+00:00Added an answer on June 5, 2026 at 7:51 pm

    here’s a quick sample, I find on the internet:

    I’ve used a placeholder to hold the dynamically created controls – the button and textboxes on that button’s click event.

    and the code:

       protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                if (ViewState["Add"] != null)
                {
                    Button add = new Button();
                    add.Text = "Add";
                    add.Click += new EventHandler(add_Click);
                    PlaceHolder1.Controls.Add(add);
                }
                if (ViewState["textboxes"] != null)
                {
                    int count = 0;
                    count = (int)ViewState["textboxes"];
                    for (int i = 0; i < count; i++)
                    {
                        textbox  textbox_foradd = new TextBox();
                        textbox_foradd.ID = "textadd" + (i + 1).ToString();
                        PlaceHolder1.Controls.Add(textbox_foradd);
                    }
                }
            }
    
        }
    
        void add_Click(object sender, EventArgs e)
        {
            int count = 1;
            if (ViewState["textboxes"] != null)
            {
                count += Convert.ToInt32(ViewState["textboxes"]);
            }
            TextBox textbox_foradd = new TextBox();
            textbox_foradd.ID = "textadd" + count.ToString();
            PlaceHolder1.Controls.Add(textbox_foradd);
            ViewState["textboxes"] = count;
        }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            Button add = new Button();
            add.Text = "Add";
            PlaceHolder1.Controls.Add(add);
            ViewState["Add"] = 1;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a question regarding a SQL-select-query: The table contains several columns, one of
I've got a query that returns a proper result set, using SQL 2005. It
I have a performance issue regarding a quite simple query that run for more
Just got query regarding c malloc() function. I am read()ing x number of bytes
I have an issue regarding link button, On my website i have got a
I have a doubt regarding database operation.I have one insert query that should run
I got a query with five joins on some rather large tables (largest table
I've got a query that looks a bit like this: select records.id, contacts.name +
I've got a query below. I want to add a condition that if the
I've got a query that's been driving me up the wall. The t-sql query

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.