问题
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
回答1:
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");
回答2:
it's probably late for the given scenario, but I had the same issue after upgrading AjaxControlToolikit version on my projects.
Problem is the ModalPopupExtender property OkControlID: in the newer versions of the toolkit server side clicked button's handler won't execute, it will be run, instead, the OnOkScript client-side code.
To restore old behavior, in my case, I had to remove OkControlID property from modal popup extender declaration tag.
Hope it helps.
回答3:
Somehow, taking my entire Modal Pop-Up Box outside of a <asp:UpdatePanel>
I had solved the problem for me. I will say I'm not extremely familiar with update panels, but it worked!
来源:https://stackoverflow.com/questions/12733658/the-event-handler-of-the-ok-button-inside-a-modal-popup-is-not-executing