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

Conditional Confirm Close window

3 Answers 157 Views
Window
This is a migrated thread and some comments may be shown as answers.
GlenB
Top achievements
Rank 1
GlenB asked on 21 May 2010, 12:27 AM
I have implemented a confirm close window for closing a RadWindow which works fine, however I want to only show the dialog if the user clicks Cancel. I have the following code:

Calling Window:
function OnClientShow(sender, arg) { 
    sender.add_beforeClose(onBeforeClose); 
 
function onBeforeClose(sender, arg) { 
    var oArg = arg.get_argument(); 
    alert(oArg.closingbutton); 
    if (oArg.closingbutton = "Cancel") { 
        function callbackFunction(arg) { 
 
            if (arg) { 
                sender.remove_beforeClose(onBeforeClose); 
                sender.close(); 
            } 
        } 
        arg.set_cancel(true); 
        radconfirm("Any unsaved data will be lost.<br /><br />Are you sure you wish to close this window?", callbackFunction, 400, 200, null, "Close this window?"); 
    } 
 

Closing window:
//Close the dialog 
function closeWindow(btndesc) { 
    var oWnd = GetRadWindow(); 
    var oArg = new Object(); 
    oArg.closingbutton = btndesc
    oWnd.close(oArg); 
 

I am getting the error Object doesn't support this property or method.

I can confirm that the text (btndesc) is "Cancel" when the function is fired, but the argument is not being received on the calling window. Any help is appreciated.

3 Answers, 1 is accepted

Sort by
0
Accepted
Fiko
Telerik team
answered on 21 May 2010, 01:25 PM
Hi GlenB,

The get_argument method does not exists in the argument object passed to the OnClientBeforeClose handler. For the time being such method exists only in the argument object passed to the CnClientClose event handler. We will do our best, however, to make it accessible in the OnClientBeforeClose event as well, but this can be done for the next official release of the control. For the time being, I recommend you to use this approach in order to achieve the desired result:

Send the argument:
//Close the dialog
function closeWindow(btndesc) {
    var oWnd = GetRadWindow();
    var oArg = new Object();
    oArg.closingbutton = btndesc;
    oWnd.MyCustomArgument=oArg;
}

Then access it in the OnClientBeforeClose event as follow:
function onBeforeClose(sender, arg) {
    var oArg = sender.MyCustomArgument;// sender is the same RadWindow object
    alert(oArg.closingbutton);
    if (oArg.closingbutton = "Cancel") {
        function callbackFunction(arg) {
  
            if (arg) {
                sender.remove_beforeClose(onBeforeClose);
                sender.close();
            }
        }
        arg.set_cancel(true);
        radconfirm("Any unsaved data will be lost.<br /><br />Are you sure you wish to close this window?", callbackFunction, 400, 200, null, "Close this window?");
    }
}

I hope this helps.

Best wishes,
Fiko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
GlenB
Top achievements
Rank 1
answered on 22 May 2010, 12:36 AM
Fiko, once again you have been a great help - thanks.

Quick note for any readers, there were a couple of minor adjustments, end result is as follows:

Calling page:
function OnClientShow(sender, arg) {  
    sender.add_beforeClose(onBeforeClose);  
}  
 
function onBeforeClose(sender, arg) {  
    var oArg = sender.MyCustomArgument; // sender is the same RadWindow object   
    if (oArg.closingbutton == "Cancel") {  
        function callbackFunction(arg) {  
            if (arg) {  
                sender.remove_beforeClose(onBeforeClose);  
                sender.close();  
            }  
        }  
        arg.set_cancel(true);  
        radconfirm("Any unsaved data will be lost.<br /><br />Are you sure you wish to close this window?", callbackFunction, 400, 200, null, "Close this window?");  
    }  

and Radwindow:
//Close the dialog  
function closeWindow(btn) {  
    var oWnd = GetRadWindow();  
    var oArg = new Object();  
    oArg.closingbutton = btn;  
    oWnd.MyCustomArgument = oArg;   
    oWnd.close(oArg);  
}  
 
0
GlenB
Top achievements
Rank 1
answered on 22 May 2010, 04:04 AM
Beware of a trap when closing the radwindow and reopening it again. If you don't use the Cancel button when closing the window (eg: used the Save button instead), the confirm dialog doesn't show and therefore doesn't clear the initial beforeclose event, causing it to multiply the next time the window is called.

To prevent this adjust the OnClientShow event:
function OnClientShow(sender, arg) { 
    sender.remove_beforeClose(onBeforeClose); 
    sender.add_beforeClose(onBeforeClose); 
 

Tags
Window
Asked by
GlenB
Top achievements
Rank 1
Answers by
Fiko
Telerik team
GlenB
Top achievements
Rank 1
Share this question
or