2012/05/01

How to open RadWindow without RadWindowManager


I liberated my RadWindows from the yoke of the RadWindowManager. Now the question is how to open such free window.
Some parts are well described in Telerik documentation.

Client side
Function window.radopen is not usable for manager-less windows. RadWindow client side API should be employed instead:
$find('FreeWindow').show();

It is worth noting that the same API can be used for RadWindow placed inside RadWindowManager.

From code behind
The only one relevant opening tool on server-side is property VisibleOnPageLoad. When the property is true, then the window is automatically shown after the page is loaded on the client. VisibleOnPageLoad is ViewState property so it has to be reset to the false after OnInit phase otherwise the window will open at all sequent postbacks (partial and full).

Is there any other possibility?

From code behind via startup script
It is the same approach as on client side but the script is registered in code behind as a startup script. Startup script registration is quite basic topic but when it comes to dealing with GETs/postbacks and partial postbacks within the same application, things are getting a little bit tricky.

A universal way how to open a RadWindow from code behind is:
function openWindowOnPageLoad(windowId) {
    var fn = function () {
        var window = $find(windowId);
        window.show();

        Sys.Application.remove_load(fn);
    };

    Sys.Application.add_load(fn);
}

Code behind:
ScriptManager.RegisterStartupScript(this, this.GetType(), "openWindow", "openWindowOnPageLoad('FreeWindow');", true);

What an odd code! Complexity is the price for robustness. Reasons are explained in this blog post.