我新建一个网页,想动态加两个textbox,而且垂直放置,但是就出现了这个错误:类型“TextBox”的控件“a”必须放在具有 runat=server 的窗体标记内。 但我form里明明有runat="server",为什么它说我错?究竟怎样动态添加textbox,请高手请教。
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
TextBox a = new TextBox();
a.ID = "a";
this.Page.Controls.Add(a); //而且这里我想2个textbox是垂直放置的,不是水平并排放置
TextBox b = new TextBox();
b.ID = "b";
this.Page.Controls.Add(b);
}
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
TextBox a = new TextBox();
a.ID = "a";
this.Page.Controls.Add(a); //而且这里我想2个textbox是垂直放置的,不是水平并排放置
TextBox b = new TextBox();
b.ID = "b";
this.Page.Controls.Add(b);
}
this.Page.Form.Controls.Add(b);
http://www.cnblogs.com/RIVERSPIRIT/articles/1331303.html
this.Page.Form.Controls.Add(a);
http://www.cnblogs.com/insus/articles/1429563.html
textbox.Style.Item("TOP") = 200
---------------
Me.FindControl("Form1").Controls.Add(textbox)