I'm creating X linkbuttons in code behind using the following code:
HTML:
<div runat="server" id="div_tables">
</div>
Backend:
LinkButton lnkB = new LinkButton();
lnkB.ID ="LB" + row.ItemArray[1].ToString() + row.ItemArray[2].ToString();
lnkB.Text = "Link to episode";
lnkB.Attributes.Add("runat", "server");
lnkB.Click += new EventHandler(lb_Clicked);
div_tables.Controls.Add(lnkB);
OnClick method:
protected void lb_Clicked(object sender, EventArgs e)
{
LinkButton b = sender as LinkButton;
b.Text = "ASD";
}
On linkbutton click the entire page reloads instead of only the lb_Clicked method. I'm sure this is a basic linkbutton question, but I really hope someone can help me. Thank you in advance
#
EDIT, Found this other post which gives a solution to the problem: Can't call Click Event on dynamic button
As Mark correctly says, the data is lost at the pageload. This post suggest to use viewstate to only recreate the desired button.