When you are creating dynamic controls, you need to attach events
manually. For design-time controls, this is done by the IDE.
---
btn.Click += new System.EventHandler(btn_Click)

private void btn_Click(object sender, EventArgs e)
{
  // Process the click event.
}
---

To answer your second question, you cannot convert a string to a
button variable directly. You would need to Find the control using
it's name in the page's control collection to obtain a reference to
the required button. This would require implicit or explicit use of
Reflection.

On Mar 11, 4:44 am, anant <[email protected]> wrote:
> I am trying to dynamicaly generate buttons on my web page
>
> using
> btn.Text = "btn" + a;
> btn.ID = "btn" + a;
>
> Panel.Controls.Add(btn);
>
> How can ia add events for such a button?? also how ca i refer to the
> button using a variable name??
>
> i mean if i write button1.Text = "Click "; it works
> but what if i want to do some thing like
>
> String name = "Button"+1;
>
> (name).Text = "Click"

Reply via email to