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

Radwindow onclientclose not firing second time around

3 Answers 436 Views
Window
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 15 May 2009, 05:42 PM
I have a problem with a Radwindow return values back to a calling page.  The code below shows the javascript call to open the windows and return the value back.  On the return it passes the value in an AJAX request which causes some text boxes to be filled with data.  The issue I have is the first time around the process works correctly and values are updated on the page but the second time, the radwindow opens but the onclientclose is not called.

function OnClientClose(oWnd, args) {
        var arg = args.get_argument();
        alert(" OnClientClose faultcode " + arg.faultcode);
        if (arg) {
            var faultcode = arg.faultcode;           
            $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("Finish," + arg.faultcode);
        }
    }

    function openwindow() {
        var oWnd = radopen("FaultTree.aspx", "FaultTreeWindow");
        return;
    }

The page structure means the radwindow is called from a usercontrol but the radwindowmanager is on the page that hosts the user control.  I've taken the ajax call out and the onclientclose is still not called again, it seems the reference to onclientclose is removed once the window is closed the first time.

The radwindowmanager declaration is shown below, has anyone got any ideas?

<telerik:RadWindowManager
            ID="RadWindowManager1"
            ShowContentDuringLoad="False"
            VisibleStatusbar="False"
            ReloadOnShow="True"
            DestroyOnClose="true"
            Width="500px"
            Height="400px"
            Modal="true"
            runat="server"
            InitialBehavior="None">
            <Windows>
                <telerik:RadWindow runat="server"
                    ID="CostDetailsWindow"
                    Behaviors="Close"                                        
                    NavigateUrl="~/CostDetails.aspx">
                </telerik:RadWindow>
                <telerik:RadWindow runat="server"
                    ID="ResourceDetailsWindow"
                    Behaviors="Close"                 
                    NavigateUrl="~/ResourceDetails.aspx">
                </telerik:RadWindow>
                <telerik:RadWindow runat="server"
                    ID="FaultTreeWindow"
                    OnClientClose="OnClientClose"
                    NavigateUrl="~/FaultTree.aspx">
                </telerik:RadWindow>
            </Windows>
    </telerik:RadWindowManager>

I'm using the 2009 Q1 version of the ASP.NET components.

Thanks for any assistance

Tim

3 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 18 May 2009, 01:21 PM
Hello Tim,

This behavior is the expected one, because you use the DestroyOnClose="true" property in the RadWindowManagers's declaration and the windows, declared in its Window collection, inherit it. In this case if you close the RadWindow it will be destroyed and then if you call the radopen() function with the ID of the closed window a new window will be created instead. The newly created window has the behavior declared in the RadWindowManager - in your case the OnClientClose declaration does not exist there.
To solve this, you could use one of the following approaches:
  • set value "false" to the DestroyOnClose property or do not declare it - DestroyOnClose is set to "false" by default
  • move the OnClientClose property to the RadWindowManager's declaration - in this case every opened window will have attached the OnClientClose function.

I hope this helps.

All the best,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Tim
Top achievements
Rank 1
answered on 22 May 2009, 10:40 AM

Hi Fiko,

Thanks for your help that did work.  Although one problem with the approach is the requirement for a single onclientclose to make it work.  I tried putting a second RadWindowManager on the page and move the windows that don't need an onclientclose to it, but it appeared to continue to call the first RadWindowManagers declaration for onclientclose.

 

This isn't a problem for my project but is this expected or a possible issue?

 

thanks

Tim

0
Fiko
Telerik team
answered on 25 May 2009, 01:38 PM
Hello Tim,

The behavior that you experience is the expected one, because of that only one RadWindowManager is allowed on the page. In case that two or more managers are declared, then the first one is used and the next ones are ignored. Your scenario, however, is possible and you need to use one of the approaches bellow in order to apply the desired functions to the desired RadWindows :
  • you can attach OnClientClose handler to the desired window by using its client-side API :
    <script type="text/javascript"
        function OnClientCloseHandler(oWindow, args) 
        { 
            alert("CLOSE"); 
        } 
     
        function openWindowAndAttachCloseHandler() 
        { 
            var oWindow = radopen("Popup.aspx""WindowName"); 
            oWindow.add_close(OnClientCloseHandler); 
        } 
    </script> 
    In this case you need to remove the OnClientClose property of the RadWindowManager's declaration. Please note that I suppose that you use the DestroyOnClose property with value "true". In other case you need to remove the handler first and then add it again :
    function openWindowAndAttachCloseHandler() 
        var oWindow = radopen("Popup.aspx""WindowName"); 
        oWindow.remove_close(OnClientCloseHandler); 
        oWindow.add_close(OnClientCloseHandler); 
  • The second approach is to check the ID of the RadWindow inside the OnClientClose handler and run your code. This allows you to apply some desired code to the desired window object.
    <script type="text/javascript"
        function OnClientCloseHandler(oWindow, args) 
        { 
            if (oWindow.get_id() == "RadWindow1"
            {//  
                alert(oWindow.get_id()); 
            } 
        } 
     
        function openWindowAndAttachCloseHandler() 
        { 
            var oWindow = radopen("Popup.aspx""RadWindow1"); 
        } 
    </script> 
I hope this helps.


Sincerely yours,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Window
Asked by
Tim
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Tim
Top achievements
Rank 1
Share this question
or