c# 后台生成表格,以及textBox控件,并后台获取生成的textBox的ID
我后台生成htmltable,不过后台获取不到tetxtbox的id,请哪位高手指点一下,代码如下
protected void showTable()
{
int TableRows = 2;
int TableCells = 3;
HtmlTable table=new HtmlTable();
HtmlTableRow tabRow = null;
HtmlTableCell TabCell = null;
table.ID = "textTable";
table.Border = 1;
table.Attributes.Add("runat", "server");
for (int i = 0; i < TableRows; i++)
{
tabRow = new HtmlTableRow();
for (int k = 0; k < TableCells; k++)
{
TabCell = new HtmlTableCell();
TextBox txt = new TextBox();
txt.ID = "txtNum" + k;
tabRow.Cells.Add(TabCell);
TabCell.InnerHtml=k.ToString();
TabCell.Controls.Add(txt);
}
table.Rows.Add(tabRow);
}
this.form1.Controls.Add(table);
}
如果这个方法放在 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
showTable();
}
}
里面,textBox获取不到,而直接放在Page_Load中不做回传判断,就可以获取到的,我现在想在判断回传的时候,也能获取到,该如何写,请高手帮帮忙啊,很急啊,
只用后台取,不想用JS获取,该如何做????? --------------------编程问答-------------------- protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["no"] = "0";
}
else
{
for (int i = 1; i <= Convert.ToInt16(ViewState["no"]); i++)
{
TextBox tb = new TextBox();
tb.ID = "tb" + i.ToString();
this.Panel1.Controls.Add(tb);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox tb = new TextBox();
ViewState["no"] = (Convert.ToInt16(ViewState["no"]) + 1).ToString();
tb.ID = "tb" + ViewState["no"].ToString();
this.Panel1.Controls.Add(tb);
}
protected void Button2_Click(object sender, EventArgs e)
{
for (int i = 1; i <= Convert.ToInt16(ViewState["no"]); i++)
{
string v = (this.Panel1.FindControl("tb" + i.ToString()) as TextBox).Text;
}
}
http://topic.csdn.net/u/20090923/12/ce7c0782-69b3-421c-93e1-a51a00097d57.html
补充:.NET技术 , C#