Good morning everybody.
I have a question related to event management and handling. Suppose I want to create a LinkButton .
protected void loadLinkButton() { ContentPlaceHolder content = (ContentPlaceHolder)this.Master.FindControl("MainContent"); LinkButton lnk = new LinkButton(); lnk.ID = "lnikBtn"; lnk.Text = "LinkButton"; lnk.Click += new System.EventHandler(lnk_Click); content.Controls.Add(lnk); }
Here is the event handler:
protected void lnk_Click(object sender, EventArgs e) { Label1.Text = "ok!"; }
If I run the loadLinkButton function inside Page_Load , everything will be fine. But when I try to start loadLinkButton by pressing a simple button, a link button will be created, but the event will not be processed.
protected void Button1_Click(object sender, EventArgs e) { loadLinkButton(); }
Is there any way to solve it? Or loadLinkButton should always be restored to Page_Load , Page_init , etc.
source share