Search code examples
c#asp.netasp.net-controls

how to add buttons in content place holder at runtime in asp.net?


In my form i have added one content place holder and also added a button within th e content place holder manually.But now i want to add a button in the same content place holder at runtime. I tried the following code, but the button is not showing in the browser... I don't know what is the problem here...

My Code...

ContentPlaceHolder content = (ContentPlaceHolder)this.Master.FindControl("maincontent");
Button newButton = new System.Web.UI.WebControls.Button();
newButton.ID = "NextButton";
newButton.Text = "Next";
newButton.Visible = true;
content.Controls.Add(newButton);

Solution

  • You've lost the size and location of your button.