Click event on dynamically created link buttons not working
<p>I want to give option to upload multiple files and then download it. I am creating link buttons Dynamically like: </p>

<pre><code> private void AddLinkButtons()
{
    string[] fileNames = (string[])Session["fileNames"];
    string[] fileUrls = (string[])Session["fileUrls"];
    if (fileNames != null)
    {
        for (int i = 0; i &lt; fileUrls.Length - 1; i++)
        {
            LinkButton lb = new LinkButton();

            phLinkButtons.Controls.Add(lb);
            lb.Text = fileNames[i];
            lb.CommandName = "url";
            lb.CommandArgument = fileUrls[i];
            lb.ID = "lbFile" + i;

            //lb.Click +=this.DownloadFile;
            lb.Attributes.Add("runat", "server");
            lb.Click += new EventHandler(this.DownloadFile);
            ////lb.Command += new CommandEventHandler(DownloadFile);

            phLinkButtons.Controls.Add(lb);
            phLinkButtons.Controls.Add(new LiteralControl("&lt;br&gt;"));

        }
    }
</code></pre>

<p>And my DownloadFile event is:</p>

<pre><code>protected void DownloadFile(object sender, EventArgs e)
{
    LinkButton lb = (LinkButton)sender;
    string url = lb.CommandArgument;

    System.IO.FileInfo file = new System.IO.FileInfo(url);
    if (file.Exists)
    {
        try
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
        }
        catch (Exception ex)
        {

        }
    }
    else
    {
        Response.Write("This file does not exist.");
    }
}
</code></pre>

<p>I am getting link buttons on screen but DownloadFile event is never called after clicking. i tried all options that are commented, but its not working. What is wrong in code?</p>
