1

I am building a website whereby people, before checking out of the shopping cart (and transferring to the payment iframe) can select which items from the shopping cart list to delete. The results from the shopping card are listed in a Repeater control. There is a Button in the Repeater which deletes a record from the database (used LINQ to SQL to do that.)

THe problem is that the ItemCommand event doesn't fire when i click the button. I tried 'response.write(test)' and it still would not work. It is as if the repeater cannot interact with the commands. It does render the results tho.

I would really appreciate if you could help me as I'm approaching a deadline and I've exhausted all the resources on the internet before turning to you guys!

Here's the code:

<asp:Repeater ID="RepeaterKoshnichka" runat="server" DataSourceID="LinqDataSource1">
    <ItemTemplate>
        <tr>
            <td background="images/message-bar.gif">
                <div class="message_head" style="float:left"><cite>Производ: <asp:Label ID="lblProizvod" CssClass="red_tx" Text='<%# Eval("Proizvod") %>' runat="server"></asp:Label> / Тип на Претплата: <asp:Label ID="lblPretplata" runat="server" Text='<%# Eval("Tip") %>' CssClass="red_tx"></asp:Label></cite></div>
                <div class="message_head" style="float:right"><cite>Цена: <asp:Label ID="lblCena" CssClass="red_tx" Text='<%# Eval("Cena") %>' runat="server"></asp:Label>&nbsp;
                    <asp:Button ID="Button2" CssClass="main_tx" CommandName="Delete" CommandArgument='<%# Eval("NDetID") %>' runat="server"
                        Text="Отстрани" /></cite>
                </div> 
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

protected void RepeaterKoshnichka_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
        if (Request.Form[e.CommandArgument.ToString()] != null)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                var nar = new DataClasses1DataContext();
                Guid detnar = new Guid(e.CommandArgument.ToString());
                var query = from c in nar.Naracka_Dets
                    where c.NDetID == detnar
                    select c;

                foreach (var c in query)
                {
                    nar.Naracka_Dets.DeleteOnSubmit(c);
                }

                nar.SubmitChanges();
                lblSuma.Text = ((Button)e.CommandSource).ToString();
            }
        }
    }
}

Your help is greatly appreciated!

Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
Dragan
  • 47
  • 1
  • 8
  • Can you (or someone with edit rights) please update so the code is readable? – Keith Feb 21 '11 at 20:56
  • possible duplicate of [ItemCommand event doesn't fire with repeater control](http://stackoverflow.com/questions/5076578/itemcommand-event-doesnt-fire-with-repeater-control) – egrunin Apr 29 '13 at 18:18

5 Answers5

1

You need to add the onitemcommand event handler link, i.e.

OnItemCommand="RepeaterKoshnichka_ItemCommand"
Keith
  • 5,311
  • 3
  • 34
  • 50
  • Yea I tried that aswell. I was doing some editing before posting here so I must've forgotten to add it back in the html. Any other suggestions?? – Dragan Feb 21 '11 at 21:00
  • What version of the .NET framework are you working with? Antiquated versions (v1.1 and below) used to have issues with events not firing on certain machines, which were addressed in service packs. – Keith Feb 21 '11 at 21:09
  • I would consider looking at the generated output/html and seeing what is rendered. If you have the event wired up correctly, it should trigger as expected. – Keith Feb 21 '11 at 21:23
  • Yeah I did go through the rendered html and it looks just fine. The funny thing is that i had the some problem @ work and now at home when I'm trying it out. Do you have any idea what the problem might be? Does the code look correct? Btw, thanks for your effort to help me. Greatly appreciated – Dragan Feb 21 '11 at 21:25
  • Yes, everything looks fine here. Try creating a new project and dumb it down to only a repeater and a button. Bind the repeater to a List (or whatever you want) and see if you can get the event to fire. Then work your way back up from there. – Keith Feb 21 '11 at 21:33
1

<asp:Button UseSubmitBehavior="False" ... />

Volodymyr
  • 11
  • 1
1

One thing to note, when you are binding, make sure you are only binding if NOT post back (or after you've processed the event) otherwise you'll lose the event.

Law Metzler
  • 1,205
  • 9
  • 11
0

I had a smimilar issue and nothing solved my problem. It ends up (after searching for a very long time) that I found that I have a textfield way higher on the page that was not validating, so I just added CausesValidation="false" to the button in the repeater and problem solved.

Daniel Valadas
  • 301
  • 3
  • 10
0

Is the post back happening for any other controls on your page? Do you have any javascript on your page like "javascript:void(0)" ?

XtremeBytes
  • 1,469
  • 8
  • 12
  • Nothing of that sort. I just have a LinqDataSource control a repeater and an iframe which is triggered by a button that's outside the repeater – Dragan Feb 21 '11 at 21:28