Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create multiple number of buttons according to the number of clicks on create button, but its creating only one button.
please help.
C#
static int i = 0;

public void createbutton()
{
    
    Response.Write(i+ " BUTTON CREATED");
    Button b = new Button();
    b.ID = "botton" + i.ToString();
    b.Text = "Remove"+i;
    b.Click += new EventHandler(b_Click);
    i=i+1;
    this.form1.Controls.Add(b);

}

protected void b_Click(object sender, EventArgs e)
{
    
    Button b = (Button)sender;
    
    b.Visible = true;
   
    Response.Write(b.Text);
    this.form1.Controls.Remove(b);
}
Posted
Updated 24-May-14 16:28pm
v2

You could try JavaScript

Example:

JavaScript
<body>
    <button id="b" onclick="make()">Create</button>
    <div id="d"></div>
    <script>
        var n = 0;

        function make() {
            var b = document.createElement("button");
            n++;
            b.innerHTML = "New Button " + n;
            document.getElementById("d").appendChild(b);
        }
    </script>
</body>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900