命令事件没有触发asp.net以动态创建控件

时间:2015-04-22 11:22:07

标签: c# asp.net

我已经获得了以下代码,可以在li html标记上动态创建图像按钮。当我单击图像按钮时,它不会触发事件。我做错了什么?

生成控件的代码:

ImageButton cmdEdit = new ImageButton();
cmdEdit.ImageUrl = "~/Images/phone_book_edit.png";
cmdEdit.ID = "cmdEdit" + recordcount.ToString();
cmdEdit.Attributes["class"] = "liQuestionsLabel2";
cmdEdit.Width = 30;
cmdEdit.CommandName = "Edit";
cmdEdit.CommandArgument = (recordcount - 1).ToString();
cmdEdit.Command += new CommandEventHandler(EditQuestion_Command);
li.Controls.Add(cmdEdit);

活动代码:

protected void EditQuestion_Command(object sender, CommandEventArgs e)
{
    Response.Write("here");
}

0 个答案:

没有答案