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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:50:33+00:00 2026-06-02T23:50:33+00:00

I am dynamically creating buttons in C# with this logic for (int i =

  • 0

I am dynamically creating buttons in C# with this logic

for (int i = 1; i <= vap; ++i)
{
    newButtons[i] = new Button();
    newButtons[i].BackColor = Color.Gray;
    newButtons[i].Name = "Button4" + i.ToString();
    newButtons[i].Click += new EventHandler(NewButtons_Click);

    newButtons[i].Location = new System.Drawing.Point(width,height);
    newButtons[i].Size = new System.Drawing.Size(76, 38);

    tabPage5.Controls.Add(newButtons[i]);
}

This is creating a button and the click event is also working but my problem is I don’t know how to get the text of the newly created button. On form load I am putting the text of button from database and this also happening correctly, but I want to know how to get the text of dynamically created buttons.

  • 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-02T23:50:34+00:00Added an answer on June 2, 2026 at 11:50 pm

    You won’t be able to get the text until after you populate it from the database (careful not to try and get the text too early).

    But this should work:

    string buttonText = FindControl("Button41").Text;
    

    Update

    Since you want the button text from within the click event, you can access the sender object:

    Button button = sender as Button;
    string buttonText = button.Text;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating buttons dynamically ... for(int i=0; i<colSize;i++){ final Button btn = new Button(this);
I'm new to iPhone dev. My app is dynamically creating buttons, following from my
After dynamically creating an element with this: $('#btnAddBanner').click(function () { var uid = new
Im dynamically creating divs with a button using this function var counter = 1;
I'm creating some 50 button dynamically. Text is getting set as followed: btn.Text=result.Rows[i]["Col1"].ToString()+"\n"+result.Rows[i]["Col2"].ToString() +"\n"+result.Rows[i]["Col3"].ToString();
I´m dynamically creating an instance of a class with reflection and this works fine,
I am creating buttons dynamically for a user-based app. Now I have to tell
I'm creating a button dynamically. The number of button is depend on the size
I am creating a gridview dynamically with a ButtonField and several BoundFields. ButtonField button
First off, I am not dynamically creating any controls. This is the order I

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.