showModalDialog icon indicating copy to clipboard operation
showModalDialog copied to clipboard

Problem with pages .aspx

Open Luengas opened this issue 10 years ago • 3 comments

Hi, in a .apsx page doesn't return OK data to the parent page. Displays the 'window alert' before closing modal window. In .HTML pages works perfectly.

$(".abrirModal2").click(function() {

    var ruta = "demoModal.aspx";

    var sFeatures = "dialogHeight: 600px; dialogWidth: 900px;";
    var o = window.showModalDialog(ruta, "", sFeatures);

   alert(o);


});

Luengas avatar Feb 20 '15 12:02 Luengas

Could you provide a URL so that I could investigate it?

niutech avatar Feb 24 '15 21:02 niutech

I have the similar problem... I like your alternative for ShowModalDialog. I have one problem using it in Asp.net Project.

  1. When ModalPopUp opens, it does not stop execution of button click event. Here is my code:

    <asp:LinkButton runat="server" ID="LnkCust" Text="Select Cust" OnClick ="LnkCust_Click" />

JavaScript code for this button:

  $('#' + '<%= LnkCust.ClientID %>').click(function (e) {
     var RetObject =  window.showModalDialog('Customer.aspx',  "",'dialogHeight:600Px;dialogWidth:1200Px;');
            alert(RetObject);
            if (RetObject == null) {
                return false;
            }
            else {
                strCustomerUniqIDList = new String(RetObject.strCustomerUniqIDList);
                strCustomerUniqNoList = new String(RetObject.strCustomerUniqNoList);
                if (strCustomerUniqIDList.length > 0) {
                    if (strCustomerUniqIDList.length > 0){
                        $('#' + '<%= TxtSelectCustomerList.ClientID %>').value = strCustomerUniqIDList;                
                    return true;
                }
                else
                    return false;
            }
}

.net code for button click:

protected void LnkCust_Click(object sender, System.EventArgs e)
{
.........
........
}

My problem is when modal dialog is open, It also executes above button click event. It should execute after modal dialog gets close.

When modal dialog is closed, nothing gets executed, not even rest of JavaScript code which is written after showModalDialog.

Please help.

pshyani avatar Nov 17 '16 16:11 pshyani

A bit late, but in case others hit this problem. You need to : a) use async/await pattern b) call event.preventDefault() to stop the form postback, c) manually postback if necessary, once the popup has closed (the __doPostBack line in the example below)

async function ShowPopUp() {
    var caller = event.target;
    event.preventDefault();
    var strOutPut = await window.showModalDialog('mypage.aspx', null, '');
    if (typeof (strOutPut) != "undefined") {
        if ((strOutPut != "") && (strOutPut == "Yes")) {
            __doPostBack(caller.id.replaceAll('_', '$'), "");
        }
    }
}

mrwoodo avatar Sep 02 '21 22:09 mrwoodo