开发者

Dynamically added button throwing error

I'm trying to dynamically add a button like so:

contentPlaceHolder cp = (ContentPlaceHolder)this.Master.FindControl("mainPageContent");
.
.
.
Button b = new Button();
b.ID = "btn" + tpnl.ClientID;
b.CssClass = "hiddenBtn";
b.CommandName = tpnl.ID;
b.Command += btnTrigger_Click;
cp.Controls.Add(b);

Now this should add my button to the placeholder (which is in a master page). I can get the content placeholder and manipulate it just fine in other areas in the code. The problem is the buttons thro开发者_如何转开发w a "Control of type 'Button' must be placed inside a form tag with runat=server" error.

I can't figure out why it's doing this - I can add other controls to the placeholder just fine in other parts of the code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜