我通过按钮点击后面的代码动态添加了文本框,它工作正常。在另一个按钮上单击我想获取所有动态添加的文本框的值。但是文本框的值是空的。如何在回发时保留动态添加的文本框的值?
aspx 代码
<asp:Table runat="server" id="placeAddTds">
<asp:TableRow>
<asp:TableCell><asp:TextBox ID="txt_from" runat="server" class="sabsw" TabIndex="88"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:TextBox ID="txt_to" runat="server" class="sabsw" TabIndex="89"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:TextBox ID="txt_per" runat="server" class="sabsw" TabIndex="90"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:Button class="main-btn add-btn pointer" runat="server" ID="btn_add" Text="Add" OnClick="TdsAddClick" TabIndex="91"></asp:Button>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
后面的代码:
protected void TdsAddClick(object sender,EventArgs e)
{
try
{
TextBox[] l1 = new TextBox[txtcount];
TextBox[] l2 = new TextBox[txtcount];
TextBox[] l3 = new TextBox[txtcount];
for (int j = 1; j < txtcount; j++)
{
l1[j] = new TextBox();
l2[j] = new TextBox();
l3[j] = new TextBox();
l1[j].ID = "txt_from" + j;
l1[j].Attributes.Add("class","sabsw");
l2[j].ID = "txt_to" + j;
l2[j].Attributes.Add("class", "sabsw");
l3[j].ID = "txt_per" + j;
l3[j].Attributes.Add("class", "sabsw");
placeAddTds.Rows.Add(new TableRow());
placeAddTds.Rows[j].Cells.Add(new TableCell());
placeAddTds.Rows[j].Cells[0].Controls.Add(l1[j]);
placeAddTds.Rows[j].Cells.Add(new TableCell());
placeAddTds.Rows[j].Cells[1].Controls.Add(l2[j]);
placeAddTds.Rows[j].Cells.Add(new TableCell());
placeAddTds.Rows[j].Cells[2].Controls.Add(l3[j]);
}
txtcount++;
}
catch (Exception ex)
{
}
}
谢谢,