I have this issue for the last few hours and i can't seem to get it right to get the child event to fire when adding a control in another control.
The hierarchy looks like this:
Placeholder control
Table control
row
cell
linkbutton control , i want this event to fire when i press the link.
When testing the code below with only one placeholder and one linkbutton the event does fire so i think it has to with something with creating the linkbutton dynamically in the table that is also in turn dynamically created.
So does anyone know how to trigger the child control events?
Doesn't work:
GeSHi (csharp):
LinkButton doSomething =
new LinkButton
();
doSomething .Text = "doSomething ";
doSomething .ID = "someID";
doSomething .
Click +=
new EventHandler
(someEvent
);
cell[j].Controls.Add(doSomething ); // does not work
//PlaceHolder1.Controls.Add(doSomething ); if i add the linkbutton to the placeholder it DOES work.
Created by GeSHI 1.0.7.20
Works:
GeSHi (csharp):
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace EventPostBackHandlerTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LinkButton l1 =
new LinkButton
();
l1.Text = "click me";
l1.
Click +=
new EventHandler
(clickMe
);
PlaceHolder1.Controls.Add(l1);
}
public void clickMe(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Test");
}
}
}
Created by GeSHI 1.0.7.20