1
我有一個簡單的頁面,1個PlaceHolder和2個按鈕(「添加行」,「獲取價值」),沒有別的。當我點擊添加行按鈕I創建一個動態表,並將一些控制在它與集ClientIDMoode電池=靜:如何訪問控制動態添加到頁面與靜態ClientIDMode
private void CreateTableWithSession(bool FirstLoad)
{
Table tbl;
int Row;
if (Session["tbl"]==null)
{
tbl = new Table();
}
else
{
tbl = (Table)Session["tbl"];
}
if (FirstLoad == true)
{
tbl.Rows.Clear();
}
//////////////////////////////////////////////////
if (Session["Row"] == null)
{
Row = 0;
}
else
{
Row = int.Parse(Session["Row"].ToString());
}
if (FirstLoad == true)
{
tbl.Rows.Clear();
}
//////////////////////////////////////////////////
TableRow tr1 = new TableRow();
TableCell tc = new TableCell();
TextBox txtBoxUserName = new TextBox();
txtBoxUserName.ClientIDMode = System.Web.UI.ClientIDMode.Static;
txtBoxUserName.Text = "0";
Col++;
txtBoxUserName.ID = "RowNo" + Row.ToString() + "ColumnNo" + Col.ToString();
tc.Controls.Add(txtBoxUserName);
tc.Width = 200;
tc.VerticalAlign = VerticalAlign.Middle;
tc.HorizontalAlign = HorizontalAlign.Center;
tr1.Cells.Add(tc);
tc = new TableCell();
TextBox txtBoxPassword = new TextBox();
txtBoxPassword.ClientIDMode = System.Web.UI.ClientIDMode.Static;
txtBoxPassword.Text = "0";
Col++;
txtBoxPassword.ID = "RowNo" + Row.ToString() + "ColumnNo" + Col.ToString();
tc.Controls.Add(txtBoxPassword);
tc.Width = 200;
tc.VerticalAlign = VerticalAlign.Middle;
tc.HorizontalAlign = HorizontalAlign.Center;
tr1.Cells.Add(tc);
tbl.Rows.Add(tr1);
Session["tbl"] = tbl;
PlaceHolder1.Controls.Add(tbl);
}
,我希望當上「獲得值」按鈕,用戶點擊,得到2倍文本框的值(即動態增加),但每一次它返回Null。
TextBox txtBoxUserName = this.FindControl("RowNo1ColumnNo1") as TextBox;
我該如何解決這個問題,並獲得文本框的值?
感謝
你可以請發佈完整的代碼,你的添加行並獲得價值按鈕的代碼? –