radAlert before closing radWindow

5 posts, 1 answers
  1. Steven Black
    Steven Black avatar
    44 posts
    Member since:
    Feb 2008

    Posted 25 May 2010 Link to this post


    I have a radWindow with the following javascript code:

    <script type="text/javascript">  
            //This code is used to provide a reference to the RadWindow "wrapper"  
            function GetRadWindow() {  
                var oWindow = null;  
                if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog  
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz az well)  
                return oWindow;  
            }  
     
            function CloseOnReload(prmMsg) {  
                if (prmMsg.length > 0) {  
                    alert(prmMsg);  
                }  
                GetRadWindow().Close();  
            }  
        </script> 

    I have the following in my code-behind:

    Dim closescript As String = "<script>CloseOnReload('" & strMsg & "')</" + "script>"  
            ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "CloseOnReload", closescript, False) 

    When I run this, I correctly get an alert message, followed by the page closing after the user hits the [OK] button.

    I would like to show a radAlert instead of the normal javascript alert.  I have a radWindowManager on the page and I changed

    alert(prmMsg);

    to

    radalert(prmMsg, null, null, 'My Title');

    This is not working though.  How can I change my alert to be a radalert instead?

    Thanks.

    Steve

  2. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 28 May 2010 Link to this post

    Hi Steven,

    I believe that this Code Library will be of help.

    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. Steven Black
    Steven Black avatar
    44 posts
    Member since:
    Feb 2008

    Posted 29 May 2010 Link to this post


    Thanks for the link.  I almost have it working now.  I have two javascript functions:

    function BeforeCloseEditPage(radWindow) {  
                var oValue = radWindow.Argument;  
                if (oValue != '') {  
                    var mySplitResult = oValue.split("!");  
                    var Reload = mySplitResult[0];  
                    var Msg = mySplitResult[1];  
     
                    if (Msg != '') {  
                        radalert(Msg, 300, 200, 'Note');  
                    }  
                }  
            }  
              
            // Called when a window is being closed.  
            function CloseEditPage(radWindow) {  
                var oValue = radWindow.Argument;  
                if (oValue != '') {  
                    var mySplitResult = oValue.split("!");  
                    var Reload = mySplitResult[0];  
                    var Msg = mySplitResult[1];  
     
                    if (Reload = 'Yes') {  
                        documentdocument.location.href = document.location.href;  
                    }  
                }  
            } 

    Function BeforeCloseEditPage is called during the OnClientBeforeClose event.  The CloseEditPage function is called during the OnClientClose event.

    My radalert is being displayed within the BeforeCloseEditPage function.  However, it immediately disappears and the page reloads (note - the Reload variable will always be a Yes if there is a message to display).  I don't have time to read the alert or hit the OK button. 




  4. Answer
    Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 02 Jun 2010 Link to this post

    Hi Steven,

    I suppose that BeforeCloseEditPage method is attached to the OnClientBeforeClose event of the RadWindow object. Please note that you need to use the second parameter (the args, as shown in the demo) in order to cancel closing the window. Your code should looks like this:
    function BeforeCloseEditPage(radWindow, args)
    {
        var oValue = "text1!text2"; // FOR EXAMPLE       radWindow.Argument;
        if (oValue != '')
        {
            var mySplitResult = oValue.split("!");
            var Reload = mySplitResult[0];
            var Msg = mySplitResult[1];
     
            if (Msg != '')
            {
                args.set_cancel(true);// Cancel closing for now
                var oAlert = radalert(Msg, 300, 200, 'Note');// Show alert message
                oAlert.add_close(alertCloseHandler);// Attacha handler which will be executed when the alert dialog is closed
                function alertCloseHandler()
                {// alert dialog is closed
                    radWindow.remove_beforeClose(BeforeCloseEditPage); // remove handler in order to avoid recursion
                    radWindow.close(); // Actual close of the window. The 'BeforeCloseEditPage' handler will not be called
                    radWindow.add_beforeClose(BeforeCloseEditPage); // Add handler again
                }
            }
        }
    }
     
    function CloseEditPage(radWindow, args)
    {
        alert("Window is closed");
        //code
    }

    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.
  5. Steven Black
    Steven Black avatar
    44 posts
    Member since:
    Feb 2008

    Posted 02 Jun 2010 Link to this post


    Thanks for the assistance.  That's exactly what I needed.

    Steve
Back to Top