我想给当满足一定条件时动态的给页面添加一个控件,于是我在Page_Load()方法中写了这样的代码:Button bt = new Button();
bt.Text = "Dymatic added";
bt.Visible = bool.Parse("true");
// 没有找到类似page.add(bt)这样的方法
但是该代码未出现在页面上。是不是控件只能加在容器内?
bt.Text = "Dymatic added";
bt.Visible = bool.Parse("true");
// 没有找到类似page.add(bt)这样的方法
但是该代码未出现在页面上。是不是控件只能加在容器内?
{ LinkButton hl=new LinkButton();
hl.ResolveUrl("TechCorp.aspx");
hl.Text="学歴"+"("+dr["S_Count"].ToString()+")"; TableCell tc1=new TableCell();
tc1.Controls.Add(hl);
TableCell tc2=new TableCell();
tc2.Controls.Add(hl);
TableCell tc3=new TableCell();
tc3.Controls.Add(hl);
TableCell tc4=new TableCell();
tc4.Controls.Add(hl);
TableCell tc5=new TableCell();
tc5.Controls.Add(hl); TableRow tr=new TableRow();
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
tr.Cells.Add(tc3);
tr.Cells.Add(tc4);
tr.Cells.Add(tc5); table.Rows.Add(tr);
}
bt.Text = "Dymatic added";
Panel p=new Panel();
p.Controls.Add(bt);
我用 this.Page.Controls.Add(bt);报出没有runat="server"的异常
“ Control 'ctl02' of type 'Button' must be placed inside a form tag with runat=server.“