-1

I'm trying to invoke a BootstrapDialog.confirm() by asp:LinkButton on a custom SharePoint WebPart this way:

<asp:LinkButton runat="server" OnClientClick="BootstrapDialogPopup(this);return false;" OnClick="btn_Click" />

And BootstrapDialog function is:

function BootstrapDialogPopup(param) {
BootstrapDialog.confirm({
    title: 'Cancel',
    message: 'Are you sure?!',
    type: BootstrapDialog.TYPE_DEFAULT,
    closable: true,
    draggable: true,
    btnCancelLabel: 'Cancel',
    btnOKLabel: 'Ok',
    btnOKClass: 'btn-warning',
    callback: function (result) {
        if (result) {
            javascript: __doPostBack(param.name, '');
        } else {
            BootstrapDialog.closeAll();
        }
    }
});

}

But, once i clicked on asp:LinkButton its server side click event(btn_Click) get called before i get the chance to choose 'Ok' or 'Cancel'.

So, My question is: How to hold the Button server event until i get the chance to choose'Ok' or 'Cancel'.

Please note that this issue occurs only on SharePoint environment.

Null
  • 511
  • 5
  • 22
  • 1
    Possible duplicate of [Prevent LinkButton post back OnClientClick not working. Why?](https://stackoverflow.com/questions/16710561/prevent-linkbutton-post-back-onclientclick-not-working-why) – mjwills Jun 08 '18 at 22:45
  • @mjwills, i couldn't find an answer on the provided link, thanks. – Null Jun 08 '18 at 22:46
  • Did you try OnClientClick="BootstrapDialogPopup(this);return false;" – Hany Habib Jun 08 '18 at 23:04
  • did you try changing your `BootstrapDialogPopup()` javascript function to `return false;`? This is how the linked article does it (and similar to Hany Habib's comment above) – Jonathan Jun 08 '18 at 23:07
  • Does https://stackoverflow.com/questions/25087883/bootstrap-dialog-confirmation-onclick-confirmation-event help? – mjwills Jun 08 '18 at 23:23
  • @mjwills nope, not in my case. – Null Jun 08 '18 at 23:26

1 Answers1

0

If your problem as mentioned that the link button is posting back, this is due to that your method BootstrapDialogPopup doesnt have return false at the end. So you have 2 choices:

1) Addreturn false;at the end of BootstrapDialogPopup()

2) Modify Your Button OnClientClick to be : OnClientClick="BootstrapDialogPopup(this);return false;"

Hany Habib
  • 1,377
  • 1
  • 10
  • 19