Let server-side postback close popup on cross click

3 posts, 1 answers
  1. Erik
    Erik avatar
    28 posts
    Member since:
    Aug 2010

    Posted 13 Dec 2011 Link to this post


    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:

    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?

  2. Answer
    Marin Bratanov
    Marin Bratanov avatar
    5929 posts

    Posted 14 Dec 2011 Link to this post

    Hello Erik,

    You can use a flag to determine whether you should cancel the event:
    var shouldCancel = true;
    function OnClientBeforeClose(sender, args)
        if (shouldCancel)
            $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.

    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
  3. Erik
    Erik avatar
    28 posts
    Member since:
    Aug 2010

    Posted 14 Dec 2011 Link to this post

    Hi Marin,

    Thanks for your response. That was just what I needed.
Back to Top