Using jquery-ui dialog as a confirm dialog with an ASP:LinkButton (how to invoke the postbck)

前端 未结 2 1508
盖世英雄少女心
盖世英雄少女心 2021-02-11 03:45

I\'d like to use jQuery UI\'s dialog to implement a confirm dialog which is shown when the user clicks a delete-link (implemented using an asp:LinkButton).
I\'m

相关标签:
2条回答
  • 2021-02-11 04:31

    If you're not doing anything more than confirming you can add an attribute to the button.

    <asp:LinkButton ID="btnDelete" runat="server" Text="Delete"
      OnClientClick="if(!confirm('Are you sure?'))return false;" CssClass="btnDelete"></asp:LinkButton>
    
    0 讨论(0)
  • 2021-02-11 04:42

    OK, here's my approach (it works, but it might not be the best solution):

    $(document).ready(function () {
      $('#dialog-confirm-cancel').dialog({
        autoOpen: false,
        modal: true,
        buttons: {
          "Delete all items": function () {
            // invoke the href (postback) of the linkbutton,
            // that triggered the confirm-dialog
            eval($(this).dialog('option', 'onOk'));
            $(this).dialog("close");
          },
          Cancel: function () { $(this).dialog("close"); }
        }
      });
    
      $('.btnDelete').click(function () {
        $('#dialog-confirm-delete')
          // pass the value of the LinkButton's href to the dialog
          .dialog('option', 'onOk', $(this).attr('href'))
          .dialog('open');
        // prevent the default action, e.g., following a link
        return false;
      });
    });
    
    0 讨论(0)
提交回复
热议问题