Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using the Jquery dialog box for the user option yes/no and want to perform something on basis of the choice. But the dialog box is not returning any bool value. So I used Alert to check the value and found the alert displaying [object Object] instead of true/ false
C#
$(function () {
           var $myDialog = $('#confirmDialog')
       .html('You are going to Lock the Record.<br/>Click OK to confirm.  Click Cancel to stop this action.')
       .dialog({
           autoOpen: false,
           modal: true,
           title: 'Confirm..?',
           buttons: { "OK": function () {
               $(this).dialog("close");

               return true;

           }, "Cancel": function () {
               $(this).dialog("close");

               return false;

           }
           }
       });
           $('#<%=LinkButton1.ClientID%>').click(function (e) {
               e.preventDefault();
               if (Page_ClientValidate()) {
                   var r = $myDialog.dialog('open');
                   alert(r); // To test the value returned
                   if (r == true) {
                       // To do something on the basis of the result
                   }
               }
               return false;

           });
       });
Posted

1 solution

No, you can't do like this. You have to call another function inside the "buttons".

See my past answer - jqueryUI dialog returning bool[^].
JavaScript
$('#id').dialog({
    autoOpen: false,
    width: 600,
    modal: true,
    buttons: {
        "Yes": function () {
            $(this).dialog('close');
            callback(true);
        },
        "No": function () {
            $(this).dialog('close');
            callback(false);
        }
    }
});

function callback(value) {
    if (value) {
        alert("Confirmed");
    } else {
        alert("Rejected");
    }
}

So, here inside callback function, you can do what you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900