[英]how to get the value of a dynamically created textbox on buttonclick
我創建了兩個動態表和文本框,如下所示:
protected void drpNetworkList_SelectedIndexChanged(object sender, EventArgs e)
{
string socialNetworkName = drpNetworkList.SelectedItem.Text;
DataSet networkdata = VoCServiceObj.GetSocailNetworkNameDetails(partnerid,socialNetworkName);
int cdount = networkdata.Tables[0].Rows.Count;
pnlViewData.Controls.Clear();
Check.Checked = true;
pnlViewData.Visible = true;
table = new Table();
table.ID = "tbl_dy";
//Brandurl
row = new TableRow();
cell = new TableCell();
Label lbl = new Label();
lbl.ID = "lbl_1";
lbl.Text = "BrandURL";
cell.Controls.Add(lbl);
row.Cells.Add(cell);
cell = new TableCell();
TextBox txt = new TextBox();
txt.ID = "textBox";
txt.Text = networkdata.Tables[0].Rows[0]["BrandDestinationURL"].ToString();
cell.Controls.Add(txt);
row.Cells.Add(cell);
table.Rows.Add(row);
for (int i = 1; i <= cdount; i++)
{
int count = i - 1;
//ProdutId
row = new TableRow();
cell = new TableCell();
Label lbl2 = new Label();
lbl2.ID = "lbl_1'" + i + "'";
lbl2.Text = "ProductID" + i + "'";
cell.Controls.Add(lbl2);
row.Cells.Add(cell);
cell = new TableCell();
TextBox txt2 = new TextBox();
txt2.ID = "textBox1" + i + "'";
txt2.Text = networkdata.Tables[0].Rows[count]["ProductID"].ToString();
cell.Controls.Add(txt2);
row.Cells.Add(cell);
table.Rows.Add(row);
//ProdutURL
row = new TableRow();
cell = new TableCell();
Label lbl3 = new Label();
lbl3.ID = "lbl_2'" + i + "'";
lbl3.Text = "ProductURL" + i + "'";
cell.Controls.Add(lbl3);
row.Cells.Add(cell);
cell = new TableCell();
TextBox txt3 = new TextBox();
txt3.ID = "textBox2" + i + "'";
txt3.Text = networkdata.Tables[0].Rows[count]["ProductDestinationURL"].ToString();
cell.Controls.Add(txt3);
row.Cells.Add(cell);
table.Rows.Add(row);
}
pnlViewData.Controls.Add(table);
}
protected void imgSave_Click(object sender, ImageClickEventArgs e)
{
TextBox tb1 = (TextBox)Page.FindControl("textBox11");
String str = string.Empty;
str = tb1.Text;
}
文本框顯示來自數據庫的默認值。我正在運行時中編輯這些值,並且希望通過按鈕單擊功能獲得這些值。 我該如何實現???
提前致謝!!
每次創建頁面時都會創建所有頁面控件。
在事件上動態創建的控件必須在下一個Init
上重新創建。
只有在ProcessPostData
之前創建的控件才能接收用戶輸入的數據。
您可以使用ViewState
記住下次必須重新創建這些控件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.