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

Let server-side postback close popup on cross click

2 Answers 85 Views
Window
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 13 Dec 2011, 05:47 PM
Hi,

I try to execute some server-side code when the cross is clicked. This code needs to deside if the window can be closed or not. I used this code for it:

OnClientBeforeClose = "function(s, e) {e.set_cancel(true);__doPostBack('" + UniqueID + "', '" + CloseDialog + "');}";


Inside the raisePostBack method I call "window.close()" client-sided if my code want the window to close.

I used parts of this sample to make this, but this is totaly handled client-side:
http://www.telerik.com/community/code-library/aspnet-ajax/window/confirm-closing-of-a-radwindow-by-using-radconfirm.aspx

My problem is that when I call the "window.close()" method client-sided the onClientBeforeClose method is executed first again and will stop the close action of the window.

Any suggestion how I can solve this problem?

Thanks!
Erik
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 14 Dec 2011, 02:09 PM
Hello Erik,

You can use a flag to determine whether you should cancel the event:
var shouldCancel = true;
function OnClientBeforeClose(sender, args)
{
    if (shouldCancel)
    {
        args.set_cancel(true);
        $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("CheckRadWindow");
    }
    shouldCancel = true;
}

and inject a script that will close the RadWindow from the code-behind (and reduce the flag to false, of course).

I am also attaching a simple page that shows this in action to the thread. It uses a session variable to simulate your logic and odd clicks close the RadWindow, even - do not: http://screencast.com/t/GY0hRcMNfH. I am also using the RadAjaxManager for ease of demonstration, yet this approach should also work with your AJAX calls.

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Erik
Top achievements
Rank 1
answered on 14 Dec 2011, 04:02 PM
Hi Marin,

Thanks for your response. That was just what I needed.
Tags
Window
Asked by
Erik
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Erik
Top achievements
Rank 1
Share this question
or