Repeater OnItemCommand event does not work

0

I'm having trouble with a Repeater in the webform, where the OnItemCommand event is not working. It should be triggered when I click the linkbutton.

Aspx code:

<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> 

Code behind C #

protected void repeaterImagens_ItemCommand(object source, RepeaterCommandEventArgs e)
{
     if (e.CommandName.Equals("excluir"))
    {
           ExcluirArquivo(e.CommandArgument.ToString());
     }
}

I tested in debug mode, clicking on Linkbutto nothing happens, nor does it call the ItemCommand event.

    
asked by anonymous 23.05.2014 / 13:58

3 answers

0

Add return false after if in OnClientClick .

That is:

OnClientClick="if (!confirm('Confirma a exclusão desta imagem?')) return false;">

Edit:

After several suggestions, the OP discovered that the error was caused because the page has the EnableViewState="false" attribute.

    
23.05.2014 / 14:10
0

Change your LinkButton to work as follows

<asp:LinkButton ID="lbExcluir" runat="server"
    CommandName="excluir"
    CommandArgument="<%# ((String)Container.DataItem) %>" 
    OnClientClick="javascript: return confirm('Confirma a exclusão desta imagem?');">
</asp:LinkButton>

If it does not work, remove javascript:

    
23.05.2014 / 14:42
0

I was able to solve it, it was another good thing to be, that was only giving problem in that part of the page. The page was set to EnableViewState="false".

Thanks for the help.

    
24.05.2014 / 01:08