This is a migrated thread and some comments may be shown as answers.

Confirm before close on nested radWindows

1 Answer 156 Views
Window
This is a migrated thread and some comments may be shown as answers.
OWMontreal
Top achievements
Rank 1
OWMontreal asked on 28 May 2013, 07:48 PM
Hi Telerik,

I am trying to display a confirm message whenever users try to close a Radwindow. It works correctly when there  is only 1 Radwindow, but got various problems in nested RadWindows(open Radwindow from another Radwindow). I tried different approaches based on samples I found in your forum. But none of them works for my scenario. 

Basically, I want to achieve the following goals:
1. Whenever users click on the close button on the active Radwindow,  the confirm should show up. If users click on OK, it should only close the active Radwindow. If users click on Cancel, user will stay on the current Radwindow.
2. Confirm message should only be displayed once. I often got duplicate confirm windows intermittently. I guess it is due to add_beforeClose got attached multiple times.
3. When I close the 2nd Radwindow and open it again from the 1st one and try to close it, the confirm prompt should be displayed again and only once. Right now, in my sample, the prompt is like in an infinite loop and cannot be closed.

Please find the code sinippets below.
function OnBeforeClose(sender, args) {
    function callbackFunction(eventArgs) {
        if (eventArgs) {
            sender.remove_beforeClose(OnBeforeClose);
            sender.close();
//            sender.add_beforeClose(OnBeforeClose)
        }
    }
    args.set_cancel(true);
    radconfirm('Are you sure you want to close this window?', callbackFunction, 400, 140, null, 'Close Window');
}

Default.aspx:
    <telerik:RadWindow runat="server" ID="RadWindow1"></telerik:RadWindow>
    <asp:Button ID="Button1" Text="open window" runat="server" OnClientClick="openWindow(); return false;" />
    <script type="text/javascript">
        function openWindow() {
            var oWindow = window.radopen("Default2.aspx", "");
            oWindow.setSize(600, 400);
            oWindow.center();
            oWindow.add_beforeClose(OnBeforeClose);
            oWindow.show();
        }
    </script>

Default2.aspx:
  <telerik:RadWindow runat="server" ID="RadWindow1"></telerik:RadWindow>

    <asp:Button ID="Button1" Text="open window" runat="server" OnClientClick="openWindow(); return false;" />
    <script type="text/javascript">
        function openWindow() {
            var oWindow = window.radopen("Default3.aspx", "");
            oWindow.setSize(400, 300);
            oWindow.center();
            oWindow.add_beforeClose(OnBeforeClose);
            oWindow.show();
        }
    </script>

Default3.aspx is just a simple page with some text.

Here are steps to reproduce my problem:
1. Open Default2 form Default and open Default3 from Default2. 
2. Close Default3 and open it again from Default2. Try to close Default3. You will get the prompt but cannot close it.

You can try different combination of those 3 pages. I want to always display confirm prompt correctly no matter how many times I open and close and no matter which Radwindow I am trying to close. Is there any way that I can make this work?

Thank you very much

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 30 May 2013, 12:16 PM
Hello,

Have you examined the following two articles on the matter:
http://www.telerik.com/help/aspnet-ajax/window-application-confirm-closing.html
http://www.telerik.com/help/aspnet-ajax/window-programming-opening-from-within-dialog.html
If all popups are shown from the main page the OnClientBeforeClose handler can be set for their manager and all will inherit it.

I am attaching here a small example that shows this in action. I am also attaching another one that shows how parent-child relationships can be created between RadWindows in such a scenario.

With the code you sent - it seems the OnClientBeforeClose handler is attached each time the popup is shown, so the second time it will be attached twice. You could add another handler to the OnClientClose event and there remove both - the one for OnClientBeforeClose and the one for OnClientClose.

Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Window
Asked by
OWMontreal
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or