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

前端 未结 2 1509
盖世英雄少女心
盖世英雄少女心 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: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;
      });
    });
    

提交回复
热议问题