我在webform中的Repeater中遇到问题,其中OnItemCommand事件不起作用。当我点击Linkbutton时,他应该被解雇。
Codigo aspx:
<asp:Repeater ID="repeaterImagens" runat="server"
OnItemCommand="repeaterImagens_ItemCommand"
OnItemDataBound="repeaterImagens_ItemDataBound">
<ItemTemplate>
...
<asp:LinkButton ID="lbExcluir" runat="server"
CommandName="excluir"
CommandArgument="<%# ((String)Container.DataItem) %>"
OnClientClick="if (!confirm('Confirma a exclusão desta imagem?'));">
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
C#背后的代码
protected void repeaterImagens_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("excluir"))
{
ExcluirArquivo(e.CommandArgument.ToString());
}
}
在调试模式下测试,单击Linkbutton没有任何反应,甚至没有调用ItemCommand事件
答案 0 :(得分:2)
更好的方法是在ItemDataBound
事件中处理链接按钮客户端确认:
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
LinkButton lb = e.Item.FindControl("lbExcluir") as LinkButton;
if (lb != null) {
lb.OnClientClick = "return confirm('Confirma a exclusão desta imagem?')";
}
}