Thursday 3 April 2014

Close the radwindow from childpage without refreshing parentpage through javascript

In parent page design

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function onClientClose(oWnd, args) {
                // get the transferred arguments
                var arg = args.get_argument();
                if (arg == '' || arg == null) {
                }
                else {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(arg);
                }
            }
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" >
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="panel1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="panel1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
<asp:Panel ID="panel1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button"  OnClick="Button1_Click"/>
 <telerik:RadWindow ID="Example" runat="server" Modal="True"  Title="example" OnClientClose="onClientClose">
        </telerik:RadWindow>
</asp:panel>


In parent page code behind


protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
       //Get Argument from childpage(popup)
            var result = e.Argument;
        }

 protected void Button1_Click(object sender, EventArgs e)
        {
           example.navigateurl="childpage.aspx";
        }


In child page design

<script type="text/javascript">

        // Get Rad Window
        function getRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow;
        }

     

        function onClientClose(arg) {
            // Pass the arguments from the dialog to the callback function on the main page.   
            getRadWindow().close(arg);
        }

    </script>

In child page code behind

string samplevariable="test";

//Place this code to pass samplevariable to parentpage without refreshing it

Page.ClientScript.RegisterStartupScript(typeof(Page), "CloseScript_" + UniqueID, "onClientClose('" + samplevariable + "');", true);