views:

218

answers:

1

i have create two linkbuttons dynamically:

            for (int i = 0; i < 2; i++)
            {
               LinkButton lb = new LinkButton();
                lb.ID = "lnk" + FileName;
                lb.Text = FileName;
                Session["file"] = FileName;
                lb.CommandArgument = FileName;
                lb.Click += new EventHandler(Lb_Click);
                Panel1.Controls.Add(lb);
                Panel1.Controls.Add(new LiteralControl("<br />"));
            }

i have got two links namely:

  1. File11
  2. File22

void Lb_Click(object sender, EventArgs e) {

string id=lb.ID;

i.e //--Here how to get link button id which is clicked (either File11 id or File22 id)--------------------

}

+1  A: 

In your event handler:

LinkButton clickedButton = (LinkButton)sender;

You could then access the ID using clickedButton.ID

Here's an MSDN walkthrough: http://msdn.microsoft.com/en-us/library/aa457091.aspx for determining senders of events.

David Neale