Showing a radconfirm on close of a window

4 posts, 0 answers
  1. Ian
    Ian avatar
    1 posts
    Member since:
    Jan 2009

    Posted 28 Jan 2009 Link to this post

    Hi,

    I've been struggling with the following problem for a couple of hours now;

    basically I am creating windows dynamically using radopen, when the user wants to close one of these windows I want to show a confirmation asking them if they are sure if they want to close the window or not (if they click ok the window closes, if they click cancel the window stays).

    I've put together the following scripts to try to achive this:

    //this code taken from http://www.telerik.com/community/forums/aspnet-ajax/window/cancelling-close-request.aspx
    Telerik.Web.UI.RadWindow.prototype.oldClose = Telerik.Web.UI.RadWindow.prototype.close;  //keep reference to old close method

    Telerik.Web.UI.RadWindow.prototype.close = function(callBackFnArg) { //override the close window's close method

        ClosingWindow = callBackFnArg;

        if (radconfirm('Are you sure?', windowClosed, 330, 100)) //rad confirm is non blocking so the if doesn't get a chance to fire

        {

            var manager = GetRadWindowManager();

            this.oldClose(callBackFnArg); //this works fine

            this.oldClose(manager.getActiveWindow()); //this also works ok

        }

    };

    //call back function for the radconfirm
    function windowClosed(arg)

    {

        if (arg)

        {

            var manager = GetRadWindowManager();

            this.oldClose(manager.getActiveWindow()); //object doesn't support this method error

            Telerik.Web.UI.RadWindow.prototype.oldClose(manager.getActiveWindow()); //doesn't do anything

            manager.closeActiveWindow(); //can't use this as we have overriden the standard close functionality

            document.getElementById('<%=btnClose.ClientID%>').click();

        }

        else

        {

            //do nothing

        }

    }

    As you can see from above the only way I can get the window to close is if I call this.Close from within the overriden window close function, if I try to close the window from within the windowClosed function I either get an error (depending on which of the lines I execute) or nothing happens, I can't use the overriden window close function because the if will never fire (because the radconfirm prompt is non blocking).

    If I replace the radconfirm with a regular javascript alert everything is fine but I'd like to use the radconfirm.

    Any ideas?

    Thanks.

  2. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 29 Jan 2009 Link to this post

    Hello Ian,

    I modified the provided code in this forum thread and now it is works with radconfirm dialog.
    Here it is:

    <script type="text/javascript"
        Telerik.Web.UI.RadWindow.prototype.oldClose = Telerik.Web.UI.RadWindow.prototype.close; 
        Telerik.Web.UI.RadWindow.prototype.close = function() 
        { 
            var oWindow = this
            function callbackFunction(arg) 
            { 
                if (arg) 
                { 
                    oWindow.oldClose(); 
                } 
     
                Telerik.Web.UI.RadWindow.prototype.close = Telerik.Web.UI.RadWindow.prototype.oldClose; 
            } 
            radconfirm("Are you sure", callbackFunction, 300, 100, null"Close RadWindow"); 
        } 
    </script> 



    In the newest release - 2008.3.1314, we implement new event in the RadWindow control that is raised when RadWindow is about to be closed. You can use this event and implement such functionality as shown below:

    <script type="text/javascript"
        function onBeforeClose(sender, arg) 
        { 
            function callbackFunction(arg) 
            { 
                if (arg) 
                { 
                    sender.remove_beforeClose(onBeforeClose); 
                    sender.close(); 
                } 
            } 
            arg.set_cancel(true); 
            radconfirm("Are you sure", callbackFunction, 300, 100, null"Close RadWindow"); 
        } 
         
        function onClientShow(sender) 
        { 
            sender.add_beforeClose(onBeforeClose); 
        } 
    </script> 

    You need to attach the onClientShow() function to the OnClientShow event of the RadWindow object.

    I hope this helps.

    All the best,
    Fiko
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ian webster
    ian webster avatar
    14 posts
    Member since:
    Jan 2006

    Posted 29 Jan 2009 Link to this post

    Hey Fiko,

    Thanks for your reply, I ran into a couple of problems though...

    I tried your first solution before getting the lastest build of the rad controls, it worked for the first window that was opened and closed but any subsequent windows closed without showing the radconfirm prompt.

    I then moved onto your second suggestion of trying the newer build of the rad controls - I see what you mean about the new event on the window manager (onClientBeforeClose) - that was exactly what I was looking for how ever I have a new set of problems now....

    first time after upgrading the controls and trying to run the page again I got this error...

    The control with ID 'RadWindowManager' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

    The page already has a asp:ScriptManager, adding a second causes a 'can't be two script managers on one page error' so I added a rad script manager instead, after getting the script manager to register its entry in the web.config I then get this error instead....

    Unable to cast object of type 'System.Web.Configuration.ScriptingProfileServiceSection' to type 'System.Web.Configuration.ScriptingProfileServiceSection'.

    I did find another post talking about this on the forums (http://www.telerik.com/community/forums/aspnet-ajax/window/unable-to-cast-object-of-type-system-web-configuration-scriptingprofileservicesection.aspx) and tried both suggestions but I am not able to fix the problem.

  5. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 30 Jan 2009 Link to this post

    Hi Ian,

    In such case, could you please open a support ticket and send me your project so we can check it? We will investigate and get back to you with solution as soon as possible.


    All the best,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top