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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:03:26+00:00 2026-05-17T22:03:26+00:00

I want to create dynamic buttons on button click event(for example., btnCreateDynamic_Click). I tried

  • 0

I want to create dynamic buttons on button click event(for example., btnCreateDynamic_Click).
I tried creating dynamic buttons on page_load event and Pre_int event.They are all working but i want to create them in button click event. How can i do this in c# asp.net?

  • 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-17T22:03:27+00:00Added an answer on May 17, 2026 at 10:03 pm

    An idea would be to create a list of buttons in which you’d store the buttons you created in btnCreateDynamic_click.

    you could have a method like:

    private Button CreateButton(string id, string name)
            {
                Button b = new Button();
                b.Text = name;
                b.ID = id;
                b.Click += new EventHandler(Button_Click);
                b.OnClientClick = "ButtonClick('" + b.ClientID + "')";
                return b;
            }
    

    in btnCreateDynamic_click you could have something like:

    Button b = CreateButton("dinamicBtn"+myDinamicButtonsList.Count.ToString(),"dinamicBtn"+myDinamicButtonsList.Count.ToString());
    myDinamicButtonsList.add(b);
    

    and in the pageLoad for example you could do something like

    foreach(button btn in myDinamicButtonsList){
        form1.Controls.Add(btn));
    }
    
    List<Button> myDinamicButtonsList = new List<Button>();
    

    myDinamicButtonsList should be stored somewhere from where it could be retrieved after each request.

    EDIT:
    In page load you could have something like this:

    if(Session["myDinamicButtons"] == null){
        List<Button> myDinamicButtonsList = new List<Button>();
        Session["myDinamicButtons"] = myDinamicButtonsList;
    }
    
    foreach(Button btn in Session["myDinamicButtons"] as List<Button>){
        form1.Controls.Add(btn));
    }
    

    i didn’t tested it but it should work.

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

Sidebar

Related Questions

I want to avoid string concatenation to create dynamic SQL query in SQL 2008.
I have created a WinForm and I added to it dynamic Buttons, how I
I want to create a UI that uses a tab control to display multiple
I would like to place buttons in various places (not in the nav bar),
I'm new to CouchDB and want to give it a try. But before I
Hey guys, have a little issue i need to figure out. I created a
I am trying to write some kind of raw html to mimic what spring
I have a large database that were used to archive tables before implementing structural
I have a dilemna that needs I've been thinking a while but still haven't
DECLARE @T INT EXEC('SELECT @T = count(user_id) FROM ( .. .. .. )') PRINT

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.