How to create controls dynamically
Hello, I want to create button control at runtime when this button click it shows some label & textbox and another button .when second button click then textbox information is added to database.when first button click then it again generate same label & textbox and button i.e repeat the control as button click.
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Feb 24, 2011, 2:54 AM EST
try this.
Button dynamicButton = new Button();
// Set Button properties
dynamicButton.Height = 40;
dynamicButton.Width = 300;
dynamicButton.BackColor = Color.Red;
dynamicButton.ForeColor = Color.Blue;
dynamicButton.Location = new Point(20, 150);
dynamicButton.Text = "I am Dynamic Button";
dynamicButton.Name = "DynamicButton";
dynamicButton.Font = new Font("Georgia", 16);
// Add a Button Click Event handler
dynamicButton.Click += new EventHandler(DynamicButton_Click);
// Add Button to the Form. Placement of the Button
// will be based on the Location and Size of button
Controls.Add(dynamicButton);
For more details [ recommended article ]
http://www.c-sharpcorner.com/UploadFile/mahesh/1150/
Suthish NairRank #92 · 22.8K reputationPosted Feb 24, 2011, 2:57 AM EST
Suthish NairRank #92 · 22.8K reputationPosted Feb 27, 2011, 7:20 AM EST