B
Brent Borovan
Good day,
I am attemping to develop an ASP.net page that dynamically adds rows
containing text box and/or listbox controls within each row. Each control
within the table needs to be "wired" to the correct event handler. However,
when we try the code as shown below, the event does not seem to fire (even
tried to set a break point in the event handler code - the break point is
never hit).
The code appears to be correct, according to some code samples we have seen
on the web.
I'm relatively new to ASP.net and any help would greatly be appreciated.
Thanks in advance. Code snippets follows...
Brent
ASPX file contains:
<asp:Table ID="MyDynamicTable" Runat="server" backColor="#ffff99"
Width="1080px" Height="25"></asp:Table>
C# Code-Behind:
protected System.Web.UI.WebControls.Table MyDynamicTable;
protected System.Web.UI.WebControls.TextBox txtBxAmount;
private void Page_Load(object sender, System.EventArgs e)
{
int numRows;
int currRowNum;
numRows = 5;
for(currRowNum = 1; currRowNum <= numRows; currRowNum++)
{
TableRow tRow = new TableRow();
MyDynamicTable.Rows.Add(tRow);
TableCell tcAmount = new TableCell();
tRow.Cells.Add(tcAmount);
// cteate new instance of textbox
txtBxAmount = new System.Web.UI.WebControls.TextBox();
txtBxAmount.ID = currRowNum.ToString();
txtBxAmount.Text = "Text box # = " + currRowNum.ToString();
txtBxAmount.TextChanged += new EventHandler(txtBxAmount_TextChanged);
tcAmount.Controls.Add(txtBxAmount);
}
}
private void txtBxAmount_TextChanged(object sender, System.EventArgs e)
{
// Let set if the event fired
txtBxAmount.BackColor = System.Drawing.Color.Aqua;
}
I am attemping to develop an ASP.net page that dynamically adds rows
containing text box and/or listbox controls within each row. Each control
within the table needs to be "wired" to the correct event handler. However,
when we try the code as shown below, the event does not seem to fire (even
tried to set a break point in the event handler code - the break point is
never hit).
The code appears to be correct, according to some code samples we have seen
on the web.
I'm relatively new to ASP.net and any help would greatly be appreciated.
Thanks in advance. Code snippets follows...
Brent
ASPX file contains:
<asp:Table ID="MyDynamicTable" Runat="server" backColor="#ffff99"
Width="1080px" Height="25"></asp:Table>
C# Code-Behind:
protected System.Web.UI.WebControls.Table MyDynamicTable;
protected System.Web.UI.WebControls.TextBox txtBxAmount;
private void Page_Load(object sender, System.EventArgs e)
{
int numRows;
int currRowNum;
numRows = 5;
for(currRowNum = 1; currRowNum <= numRows; currRowNum++)
{
TableRow tRow = new TableRow();
MyDynamicTable.Rows.Add(tRow);
TableCell tcAmount = new TableCell();
tRow.Cells.Add(tcAmount);
// cteate new instance of textbox
txtBxAmount = new System.Web.UI.WebControls.TextBox();
txtBxAmount.ID = currRowNum.ToString();
txtBxAmount.Text = "Text box # = " + currRowNum.ToString();
txtBxAmount.TextChanged += new EventHandler(txtBxAmount_TextChanged);
tcAmount.Controls.Add(txtBxAmount);
}
}
private void txtBxAmount_TextChanged(object sender, System.EventArgs e)
{
// Let set if the event fired
txtBxAmount.BackColor = System.Drawing.Color.Aqua;
}