3

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);
leppie
  • 115,091
  • 17
  • 196
  • 297
Saravanan
  • 11,372
  • 43
  • 143
  • 213

2 Answers2

1

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

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
  • thanks, here i added size by setting height and width.for giving location,we will use style.my needed location is style="margin-left: 148px".How do i assign this style for my button... – Saravanan Sep 21 '12 at 08:57
0

Drop the

ContentPlaceHolder content = (ContentPlaceHolder)this.Master.FindControl("maincontent");

Change your code to

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

Assuming that 'maincontent' is the ID you've given your placeholder, or course.

Yehuda Shapira
  • 8,460
  • 5
  • 44
  • 66