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

radAlert before closing radWindow

4 Answers 287 Views
Window
This is a migrated thread and some comments may be shown as answers.
Steven Black
Top achievements
Rank 1
Steven Black asked on 25 May 2010, 05:57 PM

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

4 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 28 May 2010, 02:11 PM
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.
0
Steven Black
Top achievements
Rank 1
answered on 29 May 2010, 05:19 AM

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. 




0
Accepted
Fiko
Telerik team
answered on 02 Jun 2010, 02:20 PM
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.
0
Steven Black
Top achievements
Rank 1
answered on 02 Jun 2010, 04:14 PM

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

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