jquery dialog confirm delete and do postback

Good Morning,

I have the below code.  I am learning jquery think I almost have this but require a little asistance to complete it.  I am using jquery dialog to confirm delete.  Dialog is working up to the point of displaying.   On click of Confirm I want to postback to the rowcommand function of the gridview and delete the record.  My problem is the __doPostBack.  I don't know how to target the gridview button that was clicked.  Can someone help me to finish this please.



<asp:UpdatePanel ID="updatepanel2" runat="server">
 <ContentTemplate>

  <div id="grid"  runat="server" class="thehide" style="position:absolute;top:200px;left:30px">
        <table><tr style="margin-top:15px;margin-bottom:15px;"><td><asp:Label ID="mymessage" runat="server" CssClass="instruct"></asp:Label></td></tr>
        </table>
           <asp:GridView ID="grdRecords" runat="server"  AutoGenerateColumns="False" Width="700px"  OnRowDataBound="grdRecords_RowDataBound" OnRowCommand="grdRecords_RowCommand"  DataKeyNames="Request_Id" AllowPaging="true" AllowSorting="true"  CssClass="mGrid"  PageSize = "35" OnSorting="grdRecords_Sorting" OnPageIndexChanging="OnPaging"> 
       <PagerStyle CssClass="pagercss" />    <Columns> 
        
           
           
           <asp:TemplateField HeaderText="Delete"><ItemTemplate>
           
                   <asp:LinkButton ID="btnDelete" runat="server" Text="Delete" CommandName="DeleteRow" CommandArgument='<%# Eval("REQUEST_ID") %>'></asp:LinkButton>
   
       </Columns> <EmptyDataTemplate><asp:Label ID="nodata" Text=" No data to display" ForeColor="Red" runat="server" Font-Size="Medium"></asp:Label></EmptyDataTemplate>
        </asp:GridView>
</div>

<div id="dialog" style="display: none">
    <span id="id"></span>
    <br />
    <b>Subject:</b> <span id="subject"></span>
    <br />
    <b>Requester:</b> <span id="requester2"></span>
    
    <br />
</div>

<script language="javascript" type="text/javascript">

    $(document).ready(function () {
        BlockUI("dvGrid");
        $.blockUI.defaults.css = {};


            $(document).on("click", "[id*=btnDelete]", function () {


                   var row = $(this).parents("tr:first");
                id = "<b>Are you sure you want to delete</b>";
                subject = row.children("td:eq(3)").text();
                requester = row.children("td:eq(4)").text() + "?";
                $("#id").html(id);
                $("#subject").html(subject);
                $("#requester2").html(requester);
                $("#dialog").dialog({
                    title: "Confirm Delete",
                    buttons: [
                                {
                                    id: "btnConfirm",
                                    text: "Confirm",
                                    click: function () {
                                //  __doPostBack($(btnDelete).attr('name'), '');
                                    $(this).dialog("close");
                                    }
                                },
                                {
                                    id: "btnCancel",
                                    text: "Cancel",
                                   click: function () {
                                        $(this).dialog("close");
                                    }
                                }
                    ],
                    open: function (event, ui) {
                        $("#btnCancel").focus();
                        $('.ui-dialog').css('z-index', 153);

                    },
                    modal: true
                });
                return false;
            });

    });
</script>

</ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="searchby" EventName="SelectedIndexChanged" /><asp:AsyncPostBackTrigger ControlID="getRecords" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="validateprepub" EventName="Click" /><asp:AsyncPostBackTrigger ControlID="validatelit" EventName="Click" />
</Triggers></asp:UpdatePanel>

Open in new window




CODEBEHIND

protected void grdRecords_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteRow")
        {
 
            LinkButton lnkBtn = (LinkButton)e.CommandSource;
            GridViewRow myRow = (GridViewRow)lnkBtn.Parent.Parent;
            GridView myGrid = (GridView)sender;

           string requestID = myGrid.DataKeys[myRow.RowIndex].Value.ToString();
          //  MessageBox.Show(requestID.ToString());
            // Delete the record 
            DeleteRecordByID(requestID);

        }

    }

Open in new window

LVL 1
thamilto0410Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
replace line 37 :
$(document).on("click", "[id*=btnDelete]", function () {
by :
$(document).on("click", "[id*=btnDelete]", function (event) {
         event.preventDefault();
         var myForm = $(this).closest("form");

Open in new window


and line 55 :
$(this).dialog("close");
by :
$(this).dialog("close");
myForm.submit();

Open in new window

0
thamilto0410Author Commented:
leakim971 thank you for your response.  However it does not work.  The dialog does show with cancel as default.  When I click confirm it does a postback because the grid refreshes but when it does postback it does not fall into the rowcommand and do the deleting?  I need to postback to the page and to the row that was clicked in the gridview and call the rowcommand function on the gridview.  Further suggestions?
0
thamilto0410Author Commented:
Was not able to get the dialog working so went with ajax extendedpopup and that allowed me to customize according to customer specifications.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thamilto0410Author Commented:
Did not get the dialog working so had to find another solution which I did on my own.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.