How to Pass the Child window data to Textbox control within RadDock on parent page?

1 posts, 0 answers
  1. Vmax
    Vmax avatar
    4 posts
    Member since:
    Apr 2015

    Posted 26 Mar Link to this post

    How to Pass the Child window data to Textbox control within RadDock on parent page?

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Parent Page code:

    01.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="radwindow_parent_child_relation_Default" %>
    02. 
    03.<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
    04. 
    05.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    07.    <head runat="server">
    08.        <title></title>
    09.        <%--This script contains the commonly used functions for all dialogs. It is referenced by all dialog pages--%>
    10.        <script src="JScript.js" type="text/javascript"></script>
    11.    </head>
    12.    <body>
    13.        <form id="form1" runat="server">
    14.            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    15.                <Scripts>
    16.                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
    17.                    </asp:ScriptReference>
    18.                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
    19.                    </asp:ScriptReference>
    20.                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
    21.                    </asp:ScriptReference>
    22.                </Scripts>
    23.            </telerik:RadScriptManager>
    24.            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    25.            </telerik:RadAjaxManager>
    26.            This is the main form. It will host all RadWindows. The JavaScript functions that are used are defined in a common
    27.            JavaScript file so they can be reused easily. In a real application each page will define what the
    28.            useDataFromChild() and generateDataForParent() functions will do, in this example they merely populate textboxes.
    29.             
    30.             
    31.            <br />
    32.            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Modal="true" OnClientClose="returnDataToParentPopup">
    33.            </telerik:RadWindowManager>
    34.             
    35.            <br />
    36.            <br />
    37.            <script type="text/javascript">
    38.                //this is the function that receives the data from the child popup and handles it on the current page
    39.                function useDataFromChild(data)
    40.                {
    41.                    document.getElementById("Textbox1").value = data;
    42.                }
    43.            </script>
    44.            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    45.                <ContentTemplate>
    46.                    <telerik:RadDockLayout ID="RadDockLayout1" Runat="server">
    47.                        <telerik:RadDockZone ID="RadDockZone1" Runat="server" Height="300px" Width="995px">
    48.                            <telerik:RadDock ID="RadDock1" Runat="server" Height="142px" Width="933px">
    49.                                <ContentTemplate>
    50.                                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="openChildDialog('first.aspx', 'firstDialog', 'First Dialog'); return false;" Text="open first dialog" />
    51.                                    <asp:TextBox ID="Textbox1" runat="server" />
    52.                                </ContentTemplate>
    53.                            </telerik:RadDock>
    54.                        </telerik:RadDockZone>
    55.                    </telerik:RadDockLayout>
    56.                </ContentTemplate>
    57.            </asp:UpdatePanel>
    58.        </form>
    59.    </body>
    60.</html>

     

    Child page code :

    01.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="first.aspx.cs" Inherits="radwindow_parent_child_relation_first" %>
    02. 
    03.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    05.    <head runat="server">
    06.        <title></title>
    07.        <script src="JScript.js" type="text/javascript"></script>
    08.    </head>
    09.    <body>
    10.        <form id="form1" runat="server">
    11.            This is the first dialog. It will open the second one and get data from it.
    12.            <asp:Button ID="Button1" Text="open second dialog" runat="server" OnClientClick="openChildDialog('second.aspx', 'secondDialog', 'Second Dialog'); return false;" />
    13.            <br />
    14.            <asp:TextBox ID="Textbox1" runat="server" />
    15.            <asp:Button ID="Button2" Text="send data to main form" runat="server" OnClientClick="generateDataForParent(); return false;" />
    16. 
    17.            <script type="text/javascript">
    18.                //this is the function that receives the data from the child popup and handles it on the current page
    19.                function useDataFromChild(data) {
    20.                    document.getElementById("Textbox1").value = data;
    21.                }
    22.                 
    23.                //each page needs to define such a function
    24.                function generateDataForParent() {
    25.                    var info = document.getElementById("Textbox1").value;
    26.                    sendDataToParent(info);
    27.                }
    28.            </script>
    29.        </form>
    30.    </body>
    31.</html>
    32.    

     

    JScript.js code :

    01.function returnDataToParentPopup(sender, args) {
    02.    //get the data that was passed and return it to the parent reference. Note that you need to know that name of the function that will handle the data there
    03.    var info = args.get_argument();
    04. 
    05.    if (sender.__parentBackReference && sender.__parentBackReference.useDataFromChild)
    06.        sender.__parentBackReference.useDataFromChild(info);
    07.}
    08. 
    09.function openChildDialog(url, wndName, title) {
    10.    //in case of erroneous arguments, add some error handling and prevention
    11.    if (!url)
    12.        url = "errorPage.aspx";
    13.    if (!wndName)
    14.        wndName = "popup_" + Math.random();
    15.    var currentWnd = GetRadWindow();
    16.    var browserWnd = window;
    17.    if (currentWnd)
    18.        browserWnd = currentWnd.BrowserWindow;
    19.    setTimeout(function () {
    20.        var wnd = browserWnd.radopen(url, wndName);
    21.        wnd.__parentBackReference = window; //pass the current window object of the page that opens the dialog so it can be used later
    22. 
    23.        if (title)
    24.            wnd.set_title(title); //you can pass more parameters for RadWindow settings, e.g., modality, dimensions, etc.
    25.        //you can even add arguments that will pass data from the parent to the child as shown here
    27.        //in the On the Dialog Page section that shows how to access custom fields in the RadWindow object and use them.
    28.        //of course, you can also use querystrings in the URL.
    29.    }, 0);
    30.}
    31. 
    32.function GetRadWindow() {
    33.    var oWindow = null;
    34.    if (window.radWindow)
    35.        oWindow = window.radWindow;
    36.    else if (window.frameElement && window.frameElement.radWindow)
    37.        oWindow = window.frameElement.radWindow;
    38.    return oWindow;
    39.}
    40. 
    41.function sendDataToParent(dataForParent) {
    42.    //pass the data object onward
    43.    GetRadWindow().close(dataForParent);
    44.     
    45.}

     

Back to Top