niutech / showModalDialog

window.showModalDialog polyfill using a <dialog> element
https://niutech.github.io/showModalDialog/demo.html
Apache License 2.0
177 stars 88 forks source link

Value is not getting returned to parent window after closing the modal window. Please help. #24

Closed VanishreeKS closed 8 years ago

VanishreeKS commented 8 years ago

My code goes like this.. I have a UserControl page..from this page onclick of hyperlink I call the ShowModalDialog window(I am using your code). The Modal window loads URL.aspx page. Onclick of Save button in the URL.aspx page..I am creating an object and sending the values back to Usercontrol page. In IE..this works fine. In Chrome, I am unable to retrieve the returned value. I tried all the way..commenting eval and using JSON.parse in the ShowModalDialog.js file..nothing worked.

UserControl code:

<a href='#' onclick='return ShowDeliveryAddress("OrderDeliveryAddress.aspx?SpecificationId=<%#Eval("ID_Specification")%>&ERPCustomerID=<%#Eval("ID_ERPCustomer")%>&AddressId=<%#Eval("FK_DeliveryAddressID")%>",this)'>
                                            <%#Eval("ShipToCustomerID_Display")%></a>

In the function ShowDeliveryAddress(), I am calling your code.

function ShowDeliveryAddress(url, sender) {

//        var addr = window.showModalDialog(url, "some argument", "dialogWidth:500px;dialogHeight:200px");
//        alert(addr + " return value");
}

The "addr", will not have any value and I will not get the alert.

URL.aspx.cs Code: On click of Save button.

**```

//Prepare javascript to send information back to the calling page
                System.Text.StringBuilder script = new System.Text.StringBuilder();
                script.Append("var o = new Object();o.delAddress = '");
                script.Append(selectedAddressDisplay);
                script.Append("';o.fkid='");
                script.Append(ddlDeliveryAddress.SelectedItem.Value);
                if (string.IsNullOrEmpty(Request.QueryString[UIConstants.QUERYKEY_ADDRESSID]))
                {
                    script.Append("';o.updateAll='Yes';");
                }
            System.Web.HttpBrowserCapabilities browser = Request.Browser;
            if (browser.Type.ToUpper().Contains("IE"))
            {
                //script.Append("';window.returnValue = o;");
                script.Append("self.close();");
            }
            else
            {
               // script.Append("'; window.parent.document.getElementById('dialog-body').contentWindow.returnValue=o;");
                //script.Append("window.dialogArguments=o;");
                script.Append("window.parent.document.getElementById('dialog-body').parentNode.close();");  
            }

            #endregion

            ClientScript.RegisterClientScriptBlock(typeof(Page), "JSScriptBlock", script.ToString(), true);
**On click of Close button**
VanishreeKS commented 8 years ago

Thanks for the lovely code and good support. The code is working perfectly fine. Thanks again for all your efforts..