1

when user change the checkbox, I want first show my custom confirm dialog message. If user select yes, I want fire the code behing event processado_CheckedChanged(object sender, EventArgs e)

I tried something like:

<asp:CheckBox ID="processado" runat="server" OnCheckedChanged="javascript:confirmingChange();" AutoPostBack="true" />

And my js:

function confirmingChange() {
     $.confirm({
        'title': 'Confirm',
        'message': 'Are you sure?',
        'buttons': {
            'Yes': {
               'action': function () {
                    __doPostBack(document.getElementById('processado'), '');
               }
            },
            'No': {
                'action': function () {
                     return false;
                }
            }
        }
    });
    return false;
}

How can I fire my codebehind event using javascript? Thanks.

oteal
  • 614
  • 2
  • 13
  • 25

2 Answers2

3

You need onchange instead of OnCheckedChanged and return true if you want postback and false otherwise.

<asp:CheckBox ID="processado" runat="server" onchange="return javascript:confirmingChange();" 
      OnCheckedChanged="ServerSideEventHandlerHere" AutoPostBack="true" />
Adil
  • 146,340
  • 25
  • 209
  • 204
  • I did that, and changed the function to just return false, and anyway it will always execute the codebehind event alone. At the HTML, the event onchange is in element and the other event is inside the (which is inside of ) – oteal Feb 20 '14 at 11:22
  • I did not get you if you can get the generated html and make a fiddle ? – Adil Feb 20 '14 at 11:25
  • try binding the event using javascript and tell if it is triggered http://jsfiddle.net/2Encd/2/ – Adil Feb 20 '14 at 11:47
3

For calling javascript you have to use "onchange" and you have to use "return".

onchange="return javascript:confirmingChange(); "

Juhi
  • 270
  • 2
  • 17
  • I did that, and changed the function to just return false, and anyway it will always execute the codebehind event alone. At the HTML, the event onchange is in element and the other event is inside the (which is inside of ) – oteal Feb 20 '14 at 11:21