Bug in N2.Context.Persister.Delete(item) ?

Mar 25, 2009 at 12:45 PM
Hi


I have an aspx-page with a repeater in which the following line of code can be found:
<asp:ImageButton ID="ImageButtonVerwijderen" runat="server" ImageUrl="~/Images/delete.png" ToolTip="Dit item verwijderen." OnClientClick="return confirm('Weet u dit zeker?');" OnClick="DeleteItem" CommandArgument='<%# Eval("ID") %>' />

In my code behind file I have the following method:
    public void DeleteItem(object sender, EventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        // find the item with ID the same as the CommandArgument from the button
        ContentItem item = N2.Context.Persister.Get<ContentItem>(Convert.ToInt32(btn.CommandArgument));
        // delete the item
        N2.Context.Persister.Delete(item);
        // page refresh
        Page.Response.Redirect(Page.Request.Url.ToString());
    }

However this does not work like it should be. When I click the delete-button I end up in the DeleteItem-method (like it should be) and it looks like the code is executed. However the item (which is normally deleted) still appears on the website. When I click the delete-button a second time it actually disappears.

What can be wrong?


Thanks in advance!
Jochen


Mar 25, 2009 at 2:46 PM
I just found that the deleted item is actually deleted in the N2 back-end. After I pressed the delete-button for the first time, the deleted item disappears in the N2 Editor back-end, but not on my aspx-page!
Coordinator
Mar 25, 2009 at 6:18 PM
Sounds like this could be a matter of timing, e.g. if data is bound during load, but deleted on click then the ui is already loaded to display the deleted items. Try either doing DataBind() after deleting or redirecting to the same page.