动态生成文本框的疑惑
请问:在下边的代码中,我动态生成文本框和按钮,当我点按钮时候怎么可以取得文本框中的值,先谢谢啦!
<% @ Page Language= "C# " %>
<script language= "C# " runat= "server ">
void Page_Load(Object sender, EventArgs e)
{
TableRow r=new TableRow();
TableCell c=new TableCell();
//*****************添加文本框******************
TextBox txtBox = new TextBox();
txtBox.ID = "txtPage ";
txtBox.Height = 18;
txtBox.Width = 40;
txtBox.MaxLength = 6;
txtBox.BorderWidth = 1;
c.Controls.Add(txtBox);
r.Cells.Add(c);
//*****************添加按钮******************
c.Controls.Add(new LiteralControl( " "));
Button btnPage = new Button();
btnPage.ID = "btnPageID ";
btnPage.Width = 30;
btnPage.Height = 18;
btnPage.BorderWidth = 1;
btnPage.Text = "GO ";
btnPage.Click += new EventHandler(btnPage_Click);
c.Controls.Add(btnPage);
DyTab.Rows.Add(r);
}
private void btnPage_Click(object sender, EventArgs e)
{
//string aa = txtPage.text; // txtBox.text;
int CurrentPageIndex = 10;
Response.Write( "你输入的数字是: " + CurrentPageIndex.ToString());
}
</script>
<form runat= "server ">
<asp:Table id= "DyTab " CellPadding=5 CellSpacing=0 Border= "1 "
BorderColor= "black " runat= "server " />
</form>
------解决方案--------------------使用Request.Form[ "文本框的name "],
------解决方案--------------------这个和三层有关系么
------解决方案--------------------可以通过page.FindControl()方法,来获得这个控件
------解决方案--------------------也可以通过Table.Control[0].Control....这样一层层来获得TextBox控件,这样应该都可以取得值
------解决方案--------------------Request.Form[ "txtPage "]