1

I am using asp.net 4.5 with c#.From repeater on delete command I want to show confirmation dialog box.If user Press "Yes" than delete that record.My delete logic is in "rep_ItemCommand" event.Here Is my Code

    <as:Pager ID="pgeImportedFiles" AutoPostBack="True" EnableViewState="true" runat="server" RepeaterControlID="rptImportFiledata" Visible="false" PageSize="10" DisplayPagerOption="Top">
        <RepeaterTemplate>
            <asp:Repeater ID="rptdata" EnableViewState="true" runat="server" OnItemCommand="rptdata_ItemCommand" >
                <ItemTemplate>                            
                        <div >
                            <asp:LinkButton ID="lbnDelete"   
                                OnClientClick="javascript:return showConfirmation('Are you sure You want to Delete this File?',this.id);"                                         
                                runat="server" CommandName="Delete" CssClass="EditBtn" CommandArgument='<%# Eval("ID") %>'>Delete</asp:LinkButton>
                        </div>    
                </ItemTemplate>
            </asp:Repeater>
        </RepeaterTemplate>
    </as:Pager>

 protected void rptdata_ItemCommand(object source, RepeaterCommandEventArgs e)
 {   
   //logic for deleteing
 }

this javascript in js file and "divDialogMessage1" and "divAlertBox1" defined in this file

    $(divDialogMessage1).html(confirmationMessage,uniqueID){
     var result = false;
        $(divAlertBox1).dialog({
            title: "Confirmation",
            buttons: {
                "Yes": function () {
                    __doPostBack(uniqueID);
                    $(this).dialog("close");
                },
                "No": function () {
                    $(this).dialog("close");
                }
            }
        });
        $(divAlertBox1).dialog('open');
        return result;}

By this dialog is display on click on delete link and page also post back if select "yes" option.But rptdata_ItemCommand not firing.

Any solution for this?

2
  • what are you returning in return result; Commented Sep 18, 2015 at 14:04
  • here edit my post.Return false value in result Commented Sep 18, 2015 at 14:07

1 Answer 1

0

Logic for deleting

protected void rptdata_ItemCommand(object source, RepeaterCommandEventArgs e)
 {   
   //logic for deleteing
    switch (e.CommandName)
            {
                case "edit":
                    MyEditFunction(e.CommandArgument.ToString());
                    break;
                case "delete":
                    MyDeleteFunction(Convert.ToInt32(e.CommandArgument));
                    break;
            }
 }

Confirmation Message

Add OnItemDataBound="AddDeleteConfirmation" to your repeater mark up and the following code in the code behind

protected void AddDeleteConfirmation(Object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
            {
                // adds a confirmation javascript to ensure that deleting the template is really what the user wants.
                ((LinkButton)e.Item.FindControl("lbnDelete")).Attributes["onclick"] = "javascript: return confirm('Are you sure you want to delete this record?')";
            }
        }
Sign up to request clarification or add additional context in comments.

3 Comments

If I use simple java-script Confirmation Box My code is also working. But I am creating a custom Confirmation Box with different style and UI. For that by dialog Box return true or false can't return after press "Yes" or "No"
And By postBack event repeater ItemCommand not called. Only page Load event calling.
Have you looked at this stackoverflow.com/questions/1570329/… It is really important to know your entire page life cycle to be able to suggest where the problem can be

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.