Repeater Onitemcommand event does not work

Asked

Viewed 335 times

0

I’m having trouble with a Repeater on the webform, where the Onitemcommand event is not working. It should be triggered when I click on the linkbutton.

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

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, when clicking on Linkbutto nothing happens, not even calls the Itemcommand event.

  • Hello @user5482, maybe the error on is in Onclientclick, I think you should put a returna explicitly, something like this: Onclientclick="Return window.confirm('Confirms the deletion of this image?');">

3 answers

0

I was able to solve it, it was something else well there, that was only a problem in this part of the page. The page was set with Enableviewstate="false".

I appreciate the help.

0


Add return false after the if no OnClientClick.

That is to say:

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

Edit:

After several suggestions, the OP found that the error was caused due to the page having the attribute EnableViewState="false".

  • I made this change, however the problem persists. It is as if nothing happened, the Itemcommand event is not called.

  • has already put the breakpoint within your ItemCommand to see if you’re at least getting in?

  • @Tafarel, I already put yes, it’s as if the event was not even called.

  • @Tafarelchicotti the only event that is ordered when clicking on the lnikbutton is the page load of the page.

  • I was able to solve it, it was something else well there, that was only a problem in this part of the page. The page was set with Enableviewstate="false".

  • @Éricosouza put the solution in a reply and when you can mark as answered in case someone has the same problem.

  • @Éricosouza It wasn’t quite that I mean, it was to mark the your reply as resolved. I will edit the question and by the conclusions of the comments, but I do not think deserve to rep in this case, it was a joint effort.

  • @Omni, just a help here. As I mark my response as resolved?

  • @Write a new answer (at the bottom of the page there is a "Add another answer" button and put your conclusions there. Unless you make a mistake you’ll have to wait 48 hours before you can accept your answer as a solution, but I think it’s the right thing to do.

Show 4 more comments

0

Change as follows your LinkButton that is to work

<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 doesn’t work, remove the javascript:

  • Tafarel, I tested both ways, and the error persists. I believe it may not be javascript, or Onclientclick event. For even without the event, the problem remains.

  • By clicking on the linkbutton it does not call any event. =[

  • @Systemwhat the page is correctly generated? There is no tag wrong closed? if you put the linkbutton out of Peater it works?

  • @Omni the page is correctly generated yes. But I will do a check again in the generated code. And the linkbutton usually works outside of the Repeater.

  • @Éricosouza a tip if you remove the ((String)Container.DataItem) and leave alone Container.DataItem is to work normally

  • the problem persists, when clicking on the linkbutton, is called the page_load event of the page.

  • but dpois of page_load it will not go to Itemcommand? pq it will pass before by load msm

  • Don’t go no, just check if it’s postback. In case, it’s being true.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.