Search code examples
c#asp.netajaxcontroltoolkitmodalpopupextender

The Event Handler of the OK button inside a Modal PopUp is not executing


Problem here is, i have a Modal PopUp Extender inside a User Control, which is called from another User Control inside a Page, inside a Master Page. The Page loads the first user control dinamically and when i want to display the modal dialog it loads the User Control into a placeholder dinamically and call the show method of the modal when the Modal Pop Up User control loads.

Inside the modal I have some TextBoxes and a Button to save some data into the database.

The problem is that the Buton onClick event doesn't fire at all. I tried adding a breakpoint in the Onload event of the Modal Control, but it doesn't get in there, oddly enough, if i place another breakpoint in Onthe load event of the Parent User Control (the one that holds the Modal PopUp) the breakpoint does stop correctly at the Parent User Control's OnLoad event. I need to use the event handler, because there's where i call the Stored Procedure to save the data into the DB.

Please note that i don't want to just close the modalpopup window, i want to validate some textboxes then save some data into the database, that's why i must us ethe event handler of the button.

Thaks for your support


Solution

  • Here is a function I use in an app where I need a modal dialog box. The buttons are actually generated by the Jquery code so it's guaranteed they events get fired:

      $(function () {
               $(".addNew").dialog({
                   autoOpen: false,
                   width: 300,
                   height: 300,
                   modal: true,
                   close: function (event, ui) {
               },
               buttons:
                       {
                           "Exclude Week": function () {
    
                               var cReason = $('#<%= ddlReasonCode.ClientID %> option:selected').text();
                               var Week = $('#<%= lblWeekChange.ClientID %>').text();
    
                               $.ajax(
                                       {
                                           type: "POST",
                                           url: "Ajax/ExcludeWeek.aspx",
                                           data: "week=" + Week + "&reasonCode=" + cReason,
                                           success: function (msg) {
                                               $('#resultDiv').text('Added to List');
    
                                           },
                                           error: function (x, e) {
                                               alert("The call to the server side failed. " + x.responseText);
                                           }
                                       }
                                   );
                                       $(this).dialog("close");
                           },
                           "Cancel": function () {
                               $(this).dialog("close");
                           }
                       }
           });
    
    
       });
    

    // THis is the code used to trigger the Dialog:

    $(".addNew").dialog("open");