Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 处理运行时添加的控件(在用户控件或WEB部件上)的事件_Asp.net_User Controls_Event Handling - Fatal编程技术网

Asp.net 处理运行时添加的控件(在用户控件或WEB部件上)的事件

Asp.net 处理运行时添加的控件(在用户控件或WEB部件上)的事件,asp.net,user-controls,event-handling,Asp.net,User Controls,Event Handling,我曾经在ASP.NET网页上通过运行时动态添加一些控件,并能够处理它们的事件,但现在我将代码放在用户控件中,但它不起作用。有什么想法吗 while (drr.Read()) { LinkButton lnkbtnDownloadFile = new LinkButton(); //name of the file ---> drr[2] lnkbtnDownloadFile.Click += new EventHandler

我曾经在ASP.NET网页上通过运行时动态添加一些控件,并能够处理它们的事件,但现在我将代码放在用户控件中,但它不起作用。有什么想法吗

    while (drr.Read())
    {
        LinkButton lnkbtnDownloadFile = new LinkButton();

        //name of the file ---> drr[2]
        lnkbtnDownloadFile.Click += new EventHandler(lnkbtnDownloadFile_Click);
        lnkbtnDownloadFile.Text = drr[2].ToString();

        PlaceHolderQuestions.Controls.Add(lnkbtnDownloadFile);
        PlaceHolderQuestions.Controls.Add(new LiteralControl("<br/>"));
    }


void lnkbtnDownloadFile_Click(object sender, EventArgs e)
{
    if (sender is LinkButton)
        DownloadFile((sender as LinkButton).Text);
}

因此,当我在事件处理程序中添加断点时,它不会停止,我知道原因。因为要将事件处理程序与控件绑定,必须再次绘制或初始化控件,这在我的代码中没有发生,这就是为什么没有触发事件