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.

2 Answers 2

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" />
Sign up to request clarification or add additional context in comments.

3 Comments

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 <span> element and the other event is inside the <input> (which is inside of <span>)
I did not get you if you can get the generated html and make a fiddle ?
try binding the event using javascript and tell if it is triggered jsfiddle.net/2Encd/2
3

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

onchange="return javascript:confirmingChange(); "

1 Comment

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 <span> element and the other event is inside the <input> (which is inside of <span>)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.