Cant get radWindow to update parent page on Window close.

4 posts, 1 answers
  1. Carlos
    Carlos avatar
    7 posts
    Member since:
    May 2014

    Posted 01 Jul 2014 Link to this post

    Hi guys,

    After searching through many topics and trying different code snippets we still are not able to update a TextBox on the parent page when the RadWindow is closed.

    We are currently using C# 2010 asp.net ajax controls.

    Parent page code from where the rad window is being opened.
    <!-- Parent Page -->
     
    <body id="Body1">
        <form id="form1" runat="server">
     
            <script type="text/javascript">
     
                function getCookie()
                {
                    if (document.cookie.length > 0) {
                        var c_name = "ConsumerID";
                        c_start = document.cookie.indexOf(c_name + "=");
                        if (c_start != -1)
                         {
                            c_start = c_start + c_name.length + 1;
                            c_end = document.cookie.indexOf(";", c_start);
                            if (c_end == -1)
                            {
                                c_end = document.cookie.length;
                            }
                            return unescape(document.cookie.substring(c_start, c_end));
                        }
                    }
                    return "";
                }
     
                function OpenConsumerWindow() {
                    var oWnd = $find('<%= FormView1.FindControl("ConsumerWindow").ClientID %>');
     
                    oWnd.setUrl('ConsumerIssue.aspx?ConsumerID=' + getCookie());
                    oWnd.show();
                    oWnd.maximize();
                }
     
            </script>
     
            <asp:FormView ID="FormView1" runat="server" DataKeyNames="ItemID" GridLines="None" OnItemCommand="FormView1_ItemCommand"  Width="100%">
                <EditItemTemplate>
                    <div>
                        <table>
                            <tr>
                                <td>
                                    <telerik:RadTextBox ID="tbConsumerInfo" runat="server" EmptyMessage="No Consumer" ReadOnly="true" BackColor="LightYellow" style="float:right;" ></telerik:RadTextBox>
                                </td>
                                <td>
                                    <telerik:RadButton ID="btnAddConsumer" runat="server" Width="16px" Height="16px" AutoPostBack="false" style="padding-top:-5px;float:right;" ToolTip="Add/Edit Consumer" CausesValidation="false" OnClientClicked="OpenConsumerWindow" Visible="false">
                                        <Image ImageUrl="Images/icons/ClipboardPlus.png"  IsBackgroundImage="true"/>
                                    </telerik:RadButton>
                                </td>
                                 
                            </tr>
                        </table>
                    </div>
     
                    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Behaviors="None"  RenderMode="Lightweight" ShowContentDuringLoad="false">
                        <Windows>
                            <telerik:RadWindow ID="ConsumerWindow" runat="server" >
                            </telerik:RadWindow>
                        </Windows>
                    </telerik:RadWindowManager>
     
                </EditItemTemplate>
            </asp:FormView>
        </form>
    </body>


    Page which is opened inside the RadWindow
    <!-- Page inide of radwindow -->
     
    <body id="ConsumerBody">
        <div id="MainDiv">
            <table>
                <tr>
                    <td>
                        <telerik:RadTextBox ID="tbConsumerInfo" runat="server" ReadOnly="true" BackColor="LightYellow" ></telerik:RadTextBox>
                    </td>
                    <td>
                        <telerik:RadButton ID="btnCheckDB" runat="server" AutoPostBack="true"  CausesValidation="true" OnClick="btnCheckDB_Click" />
                    </td>
                </tr>
            </table>
        </div>
    </body>

    Pretty much what happens is that when a user enters text into the textbox and clicks the btnCheckDB button some processing takes place in the code behind. the returned value from the database must be sent through to the parent page and the tbConsumerInfo TextBox must be updated with this data once the RadWindow is closed.

    Please would you provide some feed back on how we would achieve this.

    Thank you in advance.

  2. John
    John avatar
    3 posts
    Member since:
    Aug 2013

    Posted 01 Jul 2014 in reply to Carlos Link to this post

    I would look into the BrowserWindow method so you can call a function on the parent page and pass the return value as an argument.
    ​function CloseAndRebind(args) {
        GetRadWindow().BrowserWindow.refreshGrid(args);
    GetRadWindow().Close();
    }

    You might also consider try using the OnClientClose property of the windowmanager and have that grab the return value if stored in a cookie

    If you are still unsure checkout some of the videos online in regards to the radwindow.
    http://tv.telerik.com/products/aspnet-ajax
    Thanks John
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Jul 2014 in reply to Carlos Link to this post

    Hi Carlos,

    Please have a look into the sample code snippet to pass value from the parent page to RadWindow and vice versa.

    ASPX(Parent Page):
    <asp:FormView ID="FormView1" runat="server" GridLines="None" DataSourceID="SqlDataSource1"
        DefaultMode="Edit" Width="100%">
        <EditItemTemplate>
            <div>
                <table>
                    <tr>
                        <td>
                            <telerik:RadTextBox ID="tbConsumerInfo" runat="server" EmptyMessage="No Consumer"  ReadOnly="true" BackColor="LightYellow" Style="float: right;">
                            </telerik:RadTextBox>
                        </td>
                        <td>
                            <telerik:RadButton ID="btnAddConsumer" runat="server" AutoPostBack="false" ToolTip="Add/EditConsumer" CausesValidation="false" OnClientClicked="OpenConsumerWindow" Text="Click">
                            </telerik:RadButton>
                        </td>
                    </tr>
                </table>
            </div>
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Behaviors="None"
                OnClientClose="OnClientClose" RenderMode="Lightweight" ShowContentDuringLoad="false">
                <Windows>
                    <telerik:RadWindow ID="ConsumerWindow" runat="server">
                    </telerik:RadWindow>
                </Windows>
            </telerik:RadWindowManager>
        </EditItemTemplate>
    </asp:FormView>

    JavaScript (Parent Page):
    <script type="text/javascript">
        function OnClientClose(oWnd, args) {
            var arg = args.get_argument();
            if (arg) {
                var txtValue = arg.txtValue;
                document.getElementById('<%=FormView1.FindControl("tbConsumerInfo").ClientID%>').control.set_value(txtValue);
            }
        }
        function OpenConsumerWindow() {
            var oWnd = document.getElementById('<%=FormView1.FindControl("ConsumerWindow").ClientID%>');
            oWnd.control.setUrl('ConsumerIssue.aspx?ConsumerID=' + "3");
            oWnd.control.show();
            oWnd.control.maximize();
        }
    </script>

    ASPX(RadWindow Page ):
    <table>
        <tr>
            <td>
                <telerik:RadTextBox ID="tbConsumerInfo" runat="server" ReadOnly="true" BackColor="LightYellow">
                </telerik:RadTextBox>
            </td>
            <td>
                <telerik:RadButton ID="btnCheckDB" runat="server" AutoPostBack="true" CausesValidation="true" Text="Return Value" OnClick="btnCheckDB_Click" />
            </td>
        </tr>
    </table>

    C# (RadWindow Page):
    protected void Page_Load(object sender, EventArgs e)
    {
        string value = Request.QueryString["ConsumerID"]; // access the querystring value
        tbConsumerInfo.Text = value; // assigning that value to the textbox
    }
    protected void btnCheckDB_Click(object sender, EventArgs e)
    {
        //here your logic
        string value ="Demo Item";
        string script = "function f(){returnToParent('"+value+"'); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
    }

    JavaScript (RadWindow Page):
    <script type="text/javascript">
        function returnToParent(value) {
            var oArg = new Object();
            oArg.txtValue = value;
            var oWnd = GetRadWindow();
            if (oArg.txtValue) {
                oWnd.close(oArg);
            }
        }
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
    </script>

    Thanks,
    Princy.
  5. Carlos
    Carlos avatar
    7 posts
    Member since:
    May 2014

    Posted 02 Jul 2014 in reply to Princy Link to this post

    Good Afternoon Princy,

    Thank you for your assistance. I see that both my existing code and your code was working. the TextBox on the parent page was just never being updated.

    I had to edit your javascript a little to get it to work.

    The TextBox javascript has been updated as follows.
    function OnClientClose(oWnd, args) {
                    var arg = args.get_argument();
                    if (arg) {
                        var txtValue = arg.txtValue;
                        var txBox = document.getElementById('<%=fvIncidentEdit.FindControl("tbConsumerInfo").ClientID%>');
                        txBox.value = txtValue;
                    }
                }

    When it still wasnt working i decided to replace the textBox update with an alert. i saw that the data was being passed back it just wasnt updating the TextBox.

    I will mark your answer as correct, but if others face the same issue they can try use the alert box to check if the data is being passed back to the parent page or just using my updated javascript.

    Thank you once again.
Back to Top