dynamically creat linkbutton eventhandler
I created a dynamically link buttons, and want to pass the eventhandler to it, but it doesn't work. The function never gets called. My code is below:
Code:
LinkButton lbtnEdit = new LinkButton();
protected void Button1_Click(object sender, EventArgs e)
{
foreach (Controls c in Controls)
{
if (c is textbox)
string sTextBoxID = ((TextBox)(c)).ID;
char cLast = sTextBoxID[sTextBoxID.Length - 1];
lbtnEdit.ID = "LinkButton" + cLast;
lbtnEdit.Click += new EventHandler(lbtnEdit_Click);
DIV.Controls.Add(lbtnEdit);
}
}
}
protected void lbtnEdit_Click(object sender, EventArgs e)
{
LinkButton lbtn = (LinkButton)sender;
lbtn.ID.ToString();
AddId.Visible = false ;
}
Re: dynamically creat linkbutton eventhandler
Hey,
I take it you don't get any errors when you try and compile the application?
Have you tried stepping through the code to make sure everything is happening as you expect it to, i.e. does the Event Handler actually get assigned to the Button Click event?
Gary