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

  • Home
  • SEARCH
  • 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 7915703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:32:47+00:00 2026-06-03T14:32:47+00:00

I am making a dynamic table that will add rows whenever the add row

  • 0

I am making a dynamic table that will add rows whenever the add row button is clicked.
I am creating the button programmatically and adding it to the table header.
Below that button, and on the same column there will be delete row buttons too.

I am having a problem though, when I click the button, the event is not being called. Am I creating the button correctly? If not, then how do I do it? If I am, then do you know what the problem is?

region Add_Table_Header

    TableHeaderCell thcOne = new TableHeaderCell();
    TableHeaderCell thcTwo = new TableHeaderCell();
    TableHeaderCell thcThree = new TableHeaderCell();
    TableHeaderCell thcrFour = new TableHeaderCell();
    TableHeaderCell thcFive = new TableHeaderCell();
    TableCell thcRowAction = new TableCell(); //THIS IS THE COLUMN WITH THE 
                                              //ADD BUTTON

    thcOne.Text = "Who";
    thcTwo.Text = "Date Started";
    thcThree.Text = "Date Ended";
    thcrFour.Text = "Causes?";
    thcFive.Text = "Result";

            //HERE IS WHERE I CREATE AND ADD THE BUTTON

    Button addRowButton = new Button();
    addRowButton.Text = "Add Row";
    addRowButton.Click += new EventHandler(this.AddNewRow_Click);
    thcRowAction.Controls.Add(addRowButton);

    TableHeaderRow headerRow = new TableHeaderRow();
    headerRow.Cells.Add(thcOne);
    headerRow.Cells.Add(thcTwo);
    headerRow.Cells.Add(thcThree);
    headerRow.Cells.Add(thcrFour);
    headerRow.Cells.Add(thcFive);
    headerRow.Cells.Add(thcRowAction);

    table.Rows.Add(headerRow);

    #endregion


protected void AddNewRow_Click(object sender, EventArgs e)
    {
        if (ViewState["RowsCount"] != null)
        {
            numOfRows = Convert.ToInt32(ViewState["RowsCount"]);
            GenerateTable(numOfRows);
        }
    }

Once again, the button appears, but it does not enter the correct event method.
Thanks for your help and time 🙂

By the way when I do it declaratively such as:

<asp:Button ID="BTNAdd" runat="server" Text="Add New Row" OnClick="AddNewRow_Click" />

the event will register and work completely fine.

NEW INFO:
I have a delete button appearing too, I did not register any type of event with it, but when I click it, it does the exact same thing as the add row button, could this be because the master page or a different source is telling the buttons what to do first or by default?

THANKS 🙂

  • 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-03T14:32:49+00:00Added an answer on June 3, 2026 at 2:32 pm

    You should add the dynamic controls in the Page’s Init event handler so that the ViewState and Events are triggered appropriately.

    Try doing this:

    protected void Page_Init(object sender, EventArgs e)     
         {         
             Button btn = new Button();         
            btn.ID = "btnTest";         
             btn.Text = "I was dynamically created";         
             btn.Click += new EventHandler(btnTest_Click);         
            Panel1.Controls.Add(btn);     
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a webpage with dynamic content that enters the view with AJAX polling.
i have a problem. i m making Some wpf button Dynamic through C#.i m
I am making a dynamic web page that allows people to post their favorite
I created a dynamic table in ASP/VBScript that populates a table from a recordset.
I am making a dynamic form using table. My table was like below. <table
I am making a grid (table) showing dynamic data in Windows Phone 7. I
I'm planning on making some dynamic PHP websites and I need a free Authentication
I'm having difficulty making a dynamic AJAX form submition method for .NET WebServices. The
I'm totally familiar in making static and dynamic websites. However, I have never dealt
Did you used Dynamic websites before? you see its a good way for making

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.