G
Guest
Hi,
I am trying to dynamically create linkbuttons. They need an event handler,
so i can respond to the user's click.
I try to add the eventhandler on the fly, but when i click on the link, the
code does not execute, it just reloads the page.
Where am i going so wrong? i don't understand what's missing.
many thanks in advance.
//Creating the link buttons
for(int i=0; i<4; i++)
{
LinkButton lbtn = new LinkButton();
lbtn.ID = i;
lbtn.Text = "Delete";
btn.Click += new EventHandler(lbtn_Click);
}
//Event Handler
private void lbtn_Click(object sender, System.EventArgs e)
{
LinkButton lbtnSender = (LinkButton)sender;
Response.Write(lbtnSender.ID.ToString());
}
I am trying to dynamically create linkbuttons. They need an event handler,
so i can respond to the user's click.
I try to add the eventhandler on the fly, but when i click on the link, the
code does not execute, it just reloads the page.
Where am i going so wrong? i don't understand what's missing.
many thanks in advance.
//Creating the link buttons
for(int i=0; i<4; i++)
{
LinkButton lbtn = new LinkButton();
lbtn.ID = i;
lbtn.Text = "Delete";
btn.Click += new EventHandler(lbtn_Click);
}
//Event Handler
private void lbtn_Click(object sender, System.EventArgs e)
{
LinkButton lbtnSender = (LinkButton)sender;
Response.Write(lbtnSender.ID.ToString());
}