关于动态添加的控件取值问题!
在动态添加的一个Table中的一个TableCell中添加一个TextBox加到From后如何在提交后获得TextBox中的值?
代码如下:
<%@Page language="C#" debug=true %>
<%@import NameSpace="System.IO" %>
<script runat=server>
void Page_Load(object sender,System.EventArgs e){
if(IsPostBack){
TextBox txt1= (TextBox)t.Rows[0].Cells[1].FindControl("foldername");//找不到TextBox的值
Response.Write((string)txt.Text);
}
Table t =new Table();
TableRow tr =new TableRow();
TableCell tc_txt=new TableCell();
TableCell tc_controls=new TableCell();
TableCell tc_button=new TableCell();
tc_txt.Text="创建文件夹";
TextBox txt=new TextBox();
txt.ID="foldername";
tc_controls.Controls.Add(txt);
Button bt=new Button();
bt.Text="提交";
tc_button.Controls.Add(bt);
tr.Cells.Add(tc_txt);
tr.Cells.Add(tc_controls);
tr.Cells.Add(tc_button);
t.Rows.Add(tr);
tc_txt.Dispose();
tc_controls.Dispose();
tc_button.Dispose();
tr.Dispose();
txt.Dispose();
form1.Controls.Add(t);
}
</SCRIPT>
<html>
<head>
<title></title>
</head>
<body>
<form id=form1 runat=server>
</form>
</body>
</html>