【发布时间】:2012-10-04 20:17:25
【问题描述】:
我正在创建一个按钮并将其添加到面板中
Panel p = new Panel();
p.ID = "b_con";
p.Attributes.Add("runat", "server");
this.Controls.Add(p);
Button b = new Button();
b.Attributes.Add("value", "reply");
b.Attributes.Add("id", Convert.ToInt32(r["Message_ID"]).ToString());
b.Attributes.Add("class", "button");
b.Click += new System.EventHandler(button_Click);
p.Controls.Add(b);
我收到了这个错误 'Button' 类型的控件 'ctl01' 必须放在带有 runat=server 的表单标签内。
【问题讨论】:
-
面板是服务器控件。您无需添加
runat="server"。 Button 具有Id和Text属性。 -
在什么时候将面板添加到页面?
-
您的问题解决了吗?