[英]Repeater ItemCommand doesn't work
我在OnItemCommand事件無法正常使用的Webform的Repeater中遇到問題。 當我單擊“鏈接”按鈕時,他應該被解雇。
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());
}
}
在調試模式下進行測試,單擊“鏈接”按鈕沒有任何反應,甚至沒有調用ItemCommand事件
更好的方法是在ItemDataBound
事件中處理linkbutton客戶端確認:
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?')";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.