开发者

Dynamically added button throwing error

开发者 https://www.devze.com 2023-02-22 11:24 出处:网络
I\'m trying to dynamically add a button like so: contentPlaceHolder cp = (ContentPlaceHolder)this.Master.FindControl(\"mainPageContent\");

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

精彩评论

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