我阅读了所有相关的帖子,但仍然无法理解当前面临的问题。在 Oninit 上,我使用如下文本框创建表格,当我为文本框分配 id 时,textchanged 事件不会触发,但是当我没有分配一个它触发的 ID。无法解释为什么。请帮忙。
protected override void OnInit(EventArgs e)
{
PopulateTextBoxes();
base.OnInit(e);
}
protected void PopulateTextBoxes()
{
int quantityRequired = 0;
quantityRequired =GetQuantity();
for (int j = 0; j < quantityRequired; j++)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
TextBox tb = new TextBox();
//tb.ID = j.ToString() +":RowTbx";---> this when uncommented does not fire my tb_textChanged event while left commented the textchanged event is fired. Cant understand why? How is assigning an ID affect event Firing, I need to have the ID to further update my Db.
tb.AutoPostBack = true;
tb.TextChanged += new EventHandler(tb_TextChanged);
cell1.Controls.Add(tb);
row.Cells.Add(cell1);
TableCell cell2 = new TableCell();
CheckBox chBox = new CheckBox();
chBox.CheckedChanged += new EventHandler(chBox_CheckedChanged);
chBox.AutoPostBack = true;
cell2.Controls.Add(chBox);
row.Cells.Add(cell2);
TableCell cell3 = new TableCell();
Image img = new Image();
img.Width = Unit.Pixel(25);
img.Height = Unit.Pixel(25);
img.ImageUrl = "HttpRuntime.AppDomainAppVirtualPath" + "/Images/" +"img.jpeg";
cell3.Controls.Add(img);
row.Cells.Add(cell3);
tbl_Serial.Rows.Add(row);
}
}
private void tb_TextChanged(object sender, EventArgs e)
{
// TODO: Implement this method
//throw new NotImplementedException();
}
谢谢