Button btn = new Button();
btn.ID = "firstButton";
btn.Click += new System.EventHandler(this.btnLog_Click);
SomeParentControl.Controls.Add(btn);
btn = new Button();
btn.ID = "second";
btn.Click += new System.EventHandler(this.btnLog_Click);
SomeParentControl.Controls.Add(btn);
public void btnLog_Click(object sender, EventArgs e) {
string id = ((Button)sender).ID;
}
The controls need to be created on postback as well, so no wrapping it in a
if (!Page.IsPostBack) {}
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"hb" <> wrote in message
news:...
> Hi,
>
> When I add an asp:button (ex: id=btnLog) on home.aspx,
> I need to create btnLog_Click() event in home.aspx.cs,
> and also link this event and the button in OnInit() method
> by adding:
> this.btnLog.Click +=new System.EventHandler(this.btnLog_Click);
>
> Now, I need to generate some asp:button dynamically in
> an asp:table, and assign the event to all buttons. But in
> the event, I need to retrieve the ID of the clicked button.
>
> Would you please tell me:
> 1. how can I assign the event to a dynamically generated button?
> 2. how can I add the link between a specific button and the event in
> OnInit()
> method?
> 3. how can I retrieve the ID of the clicked button(i.e. the button
> that fires the event)?
>
> Thank you
>
> hb
>
>