Hi guys! I am at my wits end detecting which one of the dymically loaded button fired the click event(since they all have same ID and text value)
Heres the scenario:
I have created a loop to read through the records of a table and creat dynamic buttons. I have also created the button_click event. But in the event handler I can not figure out at which point of the iteration the event was fired!!
my code is:
///////////// creating the button /////////////////////////
protected void Page_Load(objec t sender, EventArgs e)
{
while (reader.Read())
{
Panel panel= new Panel();
Table t= new Table();
TableCell c3 = new TableCell();
Button button1 = new Button();
button1.Text = "hide";
button1.Click += new EventHandler(bu tton1_Click);
c3.Controls.Add (button1);
TableRow r = new TableRow();
r.Cells.Add(c3) ;
t.Rows.Add(r);
panel.Controls. Add(t);
}
}
/////////////// then in the event handler button1_click i need to figure out which one of the buttons fired this event, because by that I wish to figure out at which iteration of the loop the event-firing-button was created //////////////////////////
void button1_Click(o bject sender, EventArgs e)
{
}
any idea how to do that?i need to know it and i need it fast..!!
please help
thanx in advance!
Heres the scenario:
I have created a loop to read through the records of a table and creat dynamic buttons. I have also created the button_click event. But in the event handler I can not figure out at which point of the iteration the event was fired!!
my code is:
///////////// creating the button /////////////////////////
protected void Page_Load(objec t sender, EventArgs e)
{
while (reader.Read())
{
Panel panel= new Panel();
Table t= new Table();
TableCell c3 = new TableCell();
Button button1 = new Button();
button1.Text = "hide";
button1.Click += new EventHandler(bu tton1_Click);
c3.Controls.Add (button1);
TableRow r = new TableRow();
r.Cells.Add(c3) ;
t.Rows.Add(r);
panel.Controls. Add(t);
}
}
/////////////// then in the event handler button1_click i need to figure out which one of the buttons fired this event, because by that I wish to figure out at which iteration of the loop the event-firing-button was created //////////////////////////
void button1_Click(o bject sender, EventArgs e)
{
}
any idea how to do that?i need to know it and i need it fast..!!
please help
thanx in advance!
Comment