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

Closing a RadWindow when the Close ("X") button is clicked while passing back data.

4 Answers 903 Views
Window
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 12 Nov 2008, 05:49 PM
Hi all,

I have read through several threads about handling the close button ("X") on the RadWindow and am a little confused on what I need to do.  I am using version Q2 2008 SP2 and referenced the dlls in the 35bin

What I am trying to accomplish is the following:

There is a page with a list of items from a table.  A user clicks on a button to open up a RadWindow.  This window allows a user to add 1 or more items to a table which the rad window establishes a connection to add the data.  After each add, the identity column is stored/appended in a hidden field.  When the window is closed, the items in the hidden field are passed back to the main page using the argument property of the window before closing the window and the OnClientClose property of the RadWindowManager which in turn references a script which takes the argument to the RadAjaxManager on the page in order to to display the newly added items. 

I created close button that calls a script to return the identity(s) from the newly added items.  One of the suggestions made to me was to add the close button ("X") of the window.  After I added the behavior and when the close button ("X") of the window is clicked, the script that is coded in the window is not executed. 

Below are 2 of the links that referenced:


     Tried to implement the following code but I get a null reference when attempting get the close button in the DOM which is highlighted below:

        function OpenWindow()
        {
            radopen("http://www.google.com","RadWindow2");
            //Make sure to pass the correct window name as
            //an argument when calling the ConfirmClose() function
            ConfirmClose("RadWindow2");
        }
       
        function ConfirmClose(WinName)
        {
            var oManager = GetRadWindowManager();
            var oWnd = oManager.GetWindowByName(WinName);
            //Find the Close button on the page and attach to the
            //onclick event
            var CloseButton = document.getElementById("CloseButton" + oWnd.Id);
            CloseButton.onclick = function()
                {
                    CurrentWinName = oWnd.Id;
                    //radconfirm is non-blocking, so you will need to provide a callback function
                    radconfirm("Are you sure you want to close the window?", confirmCallBackFn);
                }
        }



       This link handles the event of the close button on the main page but I don't see how I can get the identity(s) in that method.  

Does anyone know what I would need to do?

Thanks,

Ron

4 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 13 Nov 2008, 02:49 PM
Hello Ron,

In general, you can get the name of the RadWindow by using this.get_name() and then to continue with your logic:

Telerik.Web.UI.RadWindow.prototype.old_close = Telerik.Web.UI.RadWindow.prototype.close;  
Telerik.Web.UI.RadWindow.prototype.close = function(e)  
{  
     alert(this.get_name() + " will be closed"); 
     //close the window 
     this.old_close(); 
}                                 

But in scenario like yours, to avoid writing complex logic, I would suggest to simply remove the [X] button from the toolbar by using the Behaviors property and put a closing button inside the content page - this way you will be able to easily call a confirmation dialog when needed and process your data as desired.



Best wishes,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Robert
Top achievements
Rank 1
answered on 13 Nov 2008, 06:53 PM
Is it possible to capture the event when they click the Close ("X") button and cancel the close event so the window stays open? So something like an OnBeforeClientClose event?
0
Georgi Tunev
Telerik team
answered on 14 Nov 2008, 02:32 PM
Hi Robert,

Currently there is no such event. Depending on your scenario, I suggest to either check the code in the link that Ron provided:
http://www.telerik.com/community/forums/aspnet-ajax/window/close-the-rad-window.aspx
or as an alternative to try the approach that I posted here - to remove the [X] button from the toolbar by using the Behaviors property and put a closing button inside the content page.


Kind regards,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ron
Top achievements
Rank 1
answered on 17 Nov 2008, 09:46 PM
Thanks for the info which is what I was thinking would be the answer.   

My users were hoping that we could give the window the same look and feel as when closing a dialog in many of the Microsoft Office products.

Thanks again.

Ron 
Tags
Window
Asked by
Ron
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Robert
Top achievements
Rank 1
Ron
Top achievements
Rank 1
Share this question
or