oteal
oteal

Reputation: 634

Call OnCheckedChanged event from javascript

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.

Upvotes: 1

Views: 19126

Answers (2)

Juhi
Juhi

Reputation: 270

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

onchange="return javascript:confirmingChange(); "

Upvotes: 3

Adil
Adil

Reputation: 148130

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" />

Upvotes: 3

Related Questions