"Mr Not So Know It All" <(E-Mail Removed)> wrote in message
news:fb952bb5-45d3-4967-8016-(E-Mail Removed)...
>I changed the code. I added the button to the placeholder after I
> added the dynamic button click event. Unfortunately, still no
> result. Do you have an example of a dynamic button (or control) with
> event handler that works?
>
> protected void Page_Load(object sender, EventArgs e)
> {
> btn_Click.Click +=new EventHandler(Clicked);
> }
>
> public void Clicked(object sender, EventArgs e)
> {
> Response.Write("HH");
> Button btn = new Button();
> btn.Text = "New Click";
> btn.Click += new EventHandler(btn_Click2);
> plh.Controls.Add(btn);
> }
>
> void btn_Click2(object sender, EventArgs e)
> {
> Response.Write("TT");
> }
Ok. It seems the problem is that you are creating the control at a point
during the page's lifecycle that is too late for it to correctly interact
with the rest of the page.
You should try relocating this code to an earlier stage of the page's
lifecycle, such as Page_Load or LoadViewState.
What this means is that when the first button is clicked, it will cause a
postback and thus a request for a new instance of the page. You could check
for this postback in the Page_Load event and if true, create the new button
along with its event handler.
Here are some good links on this:
http://forums.asp.net/t/1286956.aspx
http://devsushi.com/2006/08/27/aspne...eation-part-1/
-Scott