我的程序用System.Web.UI.WebControls.Table Table1动态生成一个表格,
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("选择题ID"));
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("题干"));
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("难度系数"));
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("知识点"));
r.Cells.Add(c);
Table1.Rows.Add(r);
现在的问题是想把第一个控件改成添加一个LinkButton,LinkButton需要runat=server这个怎么在程序动态解决,
这是错误提示:
System.Web.HttpException: 类型“LinkButton”的控件“_ctl0”必须放在具有 runat=server 的窗体标记内。
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("选择题ID"));
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("题干"));
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("难度系数"));
r.Cells.Add(c);
c = new TableCell();
c.Controls.Add(new LiteralControl("知识点"));
r.Cells.Add(c);
Table1.Rows.Add(r);
现在的问题是想把第一个控件改成添加一个LinkButton,LinkButton需要runat=server这个怎么在程序动态解决,
这是错误提示:
System.Web.HttpException: 类型“LinkButton”的控件“_ctl0”必须放在具有 runat=server 的窗体标记内。
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace CompositionSampleControls { public class Composition1 : Control, INamingContainer { public int Value {
get {
this.EnsureChildControls();
return Int32.Parse(((TextBox)Controls[1]).Text);
}
set {
this.EnsureChildControls();
((TextBox)Controls[1]).Text = value.ToString();
}
} protected override void CreateChildControls() { this.Controls.Add(new LiteralControl("<h3>" + "值:")); TextBox box = new TextBox();
box.Text = "0";
this.Controls.Add(box); this.Controls.Add(new LiteralControl("</h3>"));
}
}
}