Refresh Parent window on RadWindow Close

12 posts, 1 answers
  1. Curt
    Curt avatar
    27 posts
    Member since:
    Jan 2011

    Posted 22 Apr 2011 Link to this post

    Ok, so Ive read a bunch of posts on how to do this, but cant seem to get them to work. Can anyone give me some help on how to get this to work.
    Thanks
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="SchoolsAttended.ascx.cs"
        Inherits="Controls_SchoolsAttended" %>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function RowDblClick(sender, eventArgs) {
                sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
            }
            function openRadWin() {
                radopen("AddSchool.aspx", "RadWindow1");
            }
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadGrid ID="rgSchoolsAttended" runat="server" ShowStatusBar="True" AllowSorting="True"
        PageSize="7" GridLines="None" AllowPaging="True" CellSpacing="0" DataSourceID="ldsSchoolsAttended"
        AutoGenerateColumns="False" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True">
        <MasterTableView DataSourceID="ldsSchoolsAttended" DataKeyNames="SchoolAttendedID"
            TableLayout="Fixed" EditMode="InPlace" CommandItemDisplay="Bottom">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <CommandItemTemplate>
                <div style="padding: 5px 5px;">
                    <button id="rbAddSchool" runat="server" onclick="openRadWin(); return false;">
                        Add School
                    </button>
                       
                    <asp:LinkButton ID="LinkButton2" runat="server" ToolTip="Add School Atteneded" CommandName="InitInsert"
                        Visible='<%# !rgSchoolsAttended.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Huntsman/Grid/AddRecord.gif" /></asp:LinkButton>  
                    <asp:LinkButton ID="LinkButton4" runat="server" ToolTip="Refresh" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../App_Themes/Huntsman/Grid/Refresh.gif" /></asp:LinkButton>
                </div>
            </CommandItemTemplate>
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridEditCommandColumn HeaderStyle-Width="30" ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    <ItemStyle CssClass="MyImageButton" />
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="SchoolAttendedID" DataType="System.Int32" FilterControlAltText="Filter SchoolAttendedID column"
                    HeaderText="SchoolAttendedID" SortExpression="SchoolAttendedID" UniqueName="SchoolAttendedID"
                    Visible="false">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="SchoolID" DataType="System.String" FilterControlAltText="Filter SchoolID column"
                    HeaderText="SchoolID" SortExpression="SchoolID" UniqueName="SchoolID" Visible="false">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderStyle-Width="160" HeaderText="SchoolName" ItemStyle-Width="240px">
                    <ItemTemplate>
                        <%#DataBinder.Eval(Container.DataItem, "SchoolAttendedName")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="rcbSchools" DataTextField="SchoolName" DataValueField="SchoolID"
                            DataSourceID="ldsSchools" SelectedValue='<%#Bind("SchoolID") %>'>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridDateTimeColumn HeaderStyle-Width="160" DataField="BeginDate" DataType="System.DateTime"
                    FilterControlAltText="Filter BeginDate column" HeaderText="Start" SortExpression="BeginDate"
                    UniqueName="BeginDate" DataFormatString="{0:d}" Visible="false">
                </telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn HeaderStyle-Width="160" DataField="EndDate" DataType="System.DateTime"
                    FilterControlAltText="Filter EndDate column" HeaderText="End" SortExpression="EndDate"
                    UniqueName="EndDate" DataFormatString="{0:d}">
                </telerik:GridDateTimeColumn>
                <telerik:GridBoundColumn HeaderStyle-Width="60" DataField="ReceivedDegree" FilterControlAltText="Filter ReceivedDegree column"
                    HeaderText="Degree" SortExpression="ReceivedDegree" UniqueName="ReceivedDegree">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn HeaderStyle-Width="60" DataField="GPA" DataType="System.Decimal"
                    FilterControlAltText="Filter GPA column" HeaderText="GPA" SortExpression="GPA"
                    UniqueName="GPA">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Transcript" FilterControlAltText="Filter Transcript column"
                    HeaderText="Transcript" SortExpression="Transcript" UniqueName="Transcript" Visible="false">
                </telerik:GridBoundColumn>
                <telerik:GridButtonColumn HeaderStyle-Width="30" ConfirmText="Are you sure you want to delete this?"
                    ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"
                    CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <ClientSettings AllowColumnsReorder="True">
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowDblClick="RowDblClick" />
        </ClientSettings>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
        </HeaderContextMenu>
    </telerik:RadGrid>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" ShowContentDuringLoad="false" Width="400px"
                Height="400px" Top="" Title="Add School" Modal="true" Behaviors="Default" OnClientClose="RefreshParentPage">
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    <asp:LinqDataSource ID="ldsSchoolsAttended" runat="server" ContextTypeName="DAL.HuntsmanLinqDataContext"
        EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntityTypeName=""
        OnSelecting="ldsSchoolsAttended_Selecting" OrderBy="EndDate" TableName="SchoolAttendeds"
        Where="HNUMBER == @HNUMBER">
        <WhereParameters>
            <asp:QueryStringParameter Name="HNUMBER" QueryStringField="HNUMBER" Type="Int32" />
        </WhereParameters>
        <InsertParameters>
            <asp:QueryStringParameter Name="HNUMBER" QueryStringField="HNUMBER" Type="Int32" />
        </InsertParameters>
    </asp:LinqDataSource>
    <asp:LinqDataSource ID="ldsSchools" runat="server" ContextTypeName="DAL.HuntsmanLinqDataContext"
        EntityTypeName="" OrderBy="SchoolName" Select="new (SchoolID, SchoolName)" TableName="Schools">
    </asp:LinqDataSource>
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Apr 2011 Link to this post

    Hello Curt,

    You can hook the OnClientColose to the RadWindow and refresh the page using document.location.reload().

    function RefreshParentPage()//function in parent page
    {
    document.location.reload();
    }
    This function should be placed in the parent page - where your RadWindow / RadWindowManager is. This function should also be hooked to the RadWindow with the OnClientClose property.

    If you want to put the refreshing code in the content page, you need to replace document with top. This way you will refer to the topmost page which will be the one from which you open the RadWindow.
    e.g.
    function closeWin() //function in content page
    {
        var oWnd = GetRadWindow();
        oWnd.close();
        top.location.href = top.location.href;
    }


    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Curt
    Curt avatar
    27 posts
    Member since:
    Jan 2011

    Posted 26 Apr 2011 Link to this post

    Worked Great! Not sure why I couldn't get it going before.
    Thanks
  5. Mahe
    Mahe avatar
    3 posts
    Member since:
    Feb 2012

    Posted 05 Sep 2012 Link to this post

    Thanks shinu. It helped me in a flash to solve...
  6. Satyanarayan
    Satyanarayan avatar
    1 posts
    Member since:
    Jun 2013

    Posted 24 Jun 2013 Link to this post

    It helps a lot ...

    Thanks,
    Satya
  7. Stephanie
    Stephanie avatar
    139 posts
    Member since:
    Aug 2013

    Posted 13 Sep 2013 Link to this post

    I cannot get that to work for me. The window closes but the parent page does not refresh. I am opening the window with JavaScript vs the radWindow.(). Does that matter?
  8. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 18 Sep 2013 Link to this post

    Hello Stephanie,

    It does not matter how the RadWindow is opened, what is important is that it has an OnClientClose handler that will refresh the page somehow (a call to __doPostBack(), window.location.reload() or the RadAjaxManager ajaxRequest() client-side method are some options). If you share the code that is causing problems on your end we could start investigating the case. In the meantime this demo shows the general approach in action. Note also how the AJAX settings are configured and make sure yours are proper as well.


    Regards,
    Marin Bratanov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  9. Stephanie
    Stephanie avatar
    139 posts
    Member since:
    Aug 2013

    Posted 18 Sep 2013 Link to this post

    Thanks for the reply. I have been looking at your demos and forums for a few days trying to get this working. Just by chance last night I moved the OnClientClose from the RadWindow tag to the RadWindowManager tag and it works, but of course it is called when every window on that page is closed when I really only need it for the one window.

    Why does it not work on the RadWindow tag? I changed nothing else in the code...
  10. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 18 Sep 2013 Link to this post

    Hello Stephanie,

    At this point my best guess is that you get another RadWindow opened, not the one you expect. This can happen if you use radopen() and you have more than one manager on the page, then the first one is used, so a wrong instance may be created. Details on dealing with this situation are available here: http://www.telerik.com/help/aspnet-ajax/radwindow-troubleshooting-wrong-window-opened.html.

    If this is not your case I strongly advise that you post here the code that exhibits this problem so I can actually investigate it, instead of attempt to guess where the problem originates.



    Regards,
    Marin Bratanov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  11. Stephanie
    Stephanie avatar
    139 posts
    Member since:
    Aug 2013

    Posted 18 Sep 2013 Link to this post

    I am not having issues with the window opening. I am having issues with the OnClientClose not firing. I only have one RadWindowManager on the page and if I put the OnClientClose in that tag it works fine. When I move the OnClientClose to the RadWindow it does not fire. That is the issue.
  12. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 19 Sep 2013 Link to this post

    Hello Stephanie,

    If an unexpected instance is opened it is possible that it simply does not have the needed handlers attached, which is why I asked you to check for this.

    Another case where an OnClientClose handler has issues is when the AjaxControlTolkit assembly is present in the solution. It outputs modified MS AJAX scripts that break event handlers. Usually setting the DestroyOnClose property of the RadWindow to false alleviates this problem because it requires less handlers. If it does not - I advise that you test with removing the AjaxControlToolkit (delete the assembly, simply removing the reference may not be enough) to see if it helps.

    If neither of these options help - I strongly advise that you share the code that leads to the problem so we can actually investigate it, instead of attempt to guess.


    Regards,
    Marin Bratanov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  13. Stephanie
    Stephanie avatar
    139 posts
    Member since:
    Aug 2013

    Posted 20 Sep 2013 Link to this post

    I tried adding the DestroyOnClose='true' but that didn't help. I cannot at this time disable the ajax toolkit as we have other controls on that page that need it.....putting it in the RadWindowManager works fine.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017