Conditional Confirm Close window

4 posts, 1 answers
  1. GlenB
    GlenB avatar
    37 posts
    Member since:
    Apr 2010

    Posted 20 May 2010 Link to this post

    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.

  2. Answer
    Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 21 May 2010 Link to this post

    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.
  3. GlenB
    GlenB avatar
    37 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    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);  
    }  
     
  4. GlenB
    GlenB avatar
    37 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    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); 
     

Back to Top