RADWindow callbacks

Yesterday I figured out a really neat feature of the RADWindow ASP.NET control from telerik.

Calling page

Javascript

function ItemWindowClosed(radWindow, returnValue)
{
    var btnRefresh = FindObject('btnRefresh');
    if (btnRefresh != null)
    {
        btnRefresh.click();
    }
}

ASPX

<radG:RadGrid ID="itemsGrid" runat="server">
</radG:RadGrid>
<input
    id="btnRefresh"
    type="button"
    value="Refresh Grid"
    onclick='window["<%= itemsGrid.ClientID %>"].AjaxRequest("<%= itemsGrid.UniqueID %>", "Rebind");'
    style="display:none;" />

Code-Behind

protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)
{
    base.RaisePostBackEvent(source, eventArgument);
    switch (eventArgument)
    {
        case "Rebind":
            itemsGrid.Rebind();
            break;
    }
}

I used a hidden button because I have my javascript in a seperate file. If you embed your javascript within the aspx file then you could make the AjaxRequest call directly from within the ItemWindowClosed javascript function.

Dialog code

Javascript

var oWindow = GetRadWindow();
oWindow.CallBack();
oWindow.Close();

I had this in a response method to my OK and Cancel buttons. I actually wrapped it up in a little C# helper method to make things even simpler. All it does it register the above javascript as startupcode, so when the page is reloaded upon completion of the postback, the javascript code is executed. So my actual code was:-

WebHelper.CloseRadWindow(Page, "OK");
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s