0

Is it possible to fire datalist_ItemCommand function in page load after post back. It doesn't make sense but I need to achieve this.

Here is the scenerio: I have datalist control and it loaded with some person data. It has got a delete button in itemTemplate.

<ItemTemplate>
   <tr>
      <td><%# Eval("Name") %></td>
      <td><%# Eval("EMail") %></td>
      <td align="center"><asp:LinkButton ID="btnDelete" runat="server" CommandName="delete" CommandArgument='<%#Eval("id") %>' OnClientClick="confirmMe('My Program title','Are you sure ?','Yes', 'No', 'datalist1_ItemCommand'); return false;"></asp:LinkButton></td>
    </tr>
</ItemTemplate>

When delete button clicked, custom modal box showing and wait for user response. If user click yes in modal box then itemCommand function should be fired. That's why you see datalist_ItemCommand function in OnClientClick attribute.

Here is JS :

function confirmMe(title, content, button_ok, button_no, asp_control) {

    swal({
        title: title,
        text: content,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#8dc63f",
        confirmButtonText: button_ok,
        cancelButtonText: button_no,
        closeOnConfirm: false,
        closeOnCancel: true
    },
    function (result) {

        if (result === true)
            __doPostBack(asp_control, '');
    });
}
CRABOLO
  • 8,605
  • 39
  • 41
  • 68
Yasin Yörük
  • 1,500
  • 7
  • 27
  • 51

1 Answers1

0

Just call _doPostBack with appropriate id when accepting from modal, Example here

function deleteItem(uniqueID, itemID) {
    //Show dialog here
        //on accept call __doPostBack(uniqueID, ''); than close modal
        //on cancel close modal
    return false
}

and call this method on client click

OnClientClick="javascript:return deleteItem(this.name, this.alt);"
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184