This is a migrated thread and some comments may be shown as answers.

window.radWindow undefined?

5 Answers 647 Views
Window
This is a migrated thread and some comments may be shown as answers.
Stephane
Top achievements
Rank 1
Stephane asked on 12 Dec 2012, 02:18 PM
Hi everyone,

I need your help.
I added Telerik to a old project. radGrid works good, and i can open radWindow.
I have followed this demo http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window

But for now, i can't close the radWindow, the reason : window.radWindow and window.frameElement.radWindow from GetRadWindow() script function are undefined.

If someone can help me.

My code :
default.aspx
<telerik:RadScriptManager runat="server" EnableViewState="false" ID="RadScriptManager1" />
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
             
            function ShowEditForm(id, rowIndex) {
                var anneeID = 0;
                var typeRessID = 0;
                var grid = $find("<%= RadGrid1.ClientID %>");
                var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
 
                anneeID = document.getElementById("<%= cboAnnees.ClientID %>").value;
                if (document.getElementById("rbResident").checked == true) {
                    typeRessID = 1;
                }
                if (document.getElementById("rbExterne").checked == true) {
                    typeRessID = 2;
                }
                if (document.getElementById("rbAutre").checked == true) {
                    typeRessID = 3;
                }
                 
                grid.get_masterTableView().selectItem(rowControl, true);
 
                window.radopen("UpdateInfo.aspx?ID=" + id + "&TYPERESSID=" + typeRessID + "&ANNEEID=" + anneeID, "UserListDialog");
                return false;
            }
             
            function ShowInsertForm() {
                window.radopen("UpdateRessourceFrameset.aspx", "UserListDialog");
                return false;
            }
            function refreshGrid(arg) {
                if (!arg) {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                }
                else {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                }
            }
            
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

<telerik:RadGrid OnItemCreated="RadGrid1_ItemCreated" ID="RadGrid1" runat="server"
        AllowPaging="True" EnableViewState="true" Width="97%">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <MasterTableView pagesEnableViewState="true" AutoGenerateColumns="False" DataKeyNames="RESS_ID" ShowHeadersWhenNoRecords="false" ClientDataKeyNames="RESS_ID"
            Width="100%" PageSize="20">
            <Columns>
                <telerik:GridBoundColumn DataField="INFO2" HeaderText="Year" ReadOnly="True">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="INFO1" HeaderText="Name"/>
                 
                <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                    <ItemTemplate>
                         
                        <asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
            <CommandItemTemplate>
                <a href="#" onclick="return ShowInsertForm();">No records...</a>
            </CommandItemTemplate>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="false"></Selecting>
             
        </ClientSettings>
    </telerik:RadGrid>
             
            <telerik:RadWindowManager ID="RadWindowManager1" EnableViewState="False" runat="server">
        <Windows>
            <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editer une ressource" Height="500px"
                Width="930px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false"
                Modal="true">
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>

default.aspx.vb
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
       If e.Argument = "Rebind" Then
           RadGrid1.MasterTableView.SortExpressions.Clear()
           RadGrid1.MasterTableView.GroupByExpressions.Clear()
           RadGrid1.Rebind()
       ElseIf e.Argument = "RebindAndNavigate" Then
           RadGrid1.MasterTableView.SortExpressions.Clear()
           RadGrid1.MasterTableView.GroupByExpressions.Clear()
           RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1
           RadGrid1.Rebind()
       End If
   End Sub
 
   Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)
       If TypeOf e.Item Is GridDataItem Then
           Dim editLink As HyperLink = DirectCast(e.Item.FindControl("EditLink"), HyperLink)
           editLink.Attributes("href") = "#"
           editLink.Attributes("onclick") = [String].Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("RESS_ID"), e.Item.ItemIndex)
       End If
   End Sub

Updateinfo.aspx
<script type="text/javascript">
     function CloseAndRebind(args) {
         GetRadWindow().BrowserWindow.refreshGrid(args);
         GetRadWindow().close();
     }
 
     function GetRadWindow() {
        var oWindow = null;
         if (window.radWindow) oWindow = window.radWindow;
         else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
 
         return oWindow;
     }
 
     function CancelEdit() {
         window.UserListDialog.close();
     }
        </script>
 
 
....
 
<asp:ScriptManager id="smUpdateRess" runat="server" />
 
<asp:DetailsView runat="server" ID="DetailsView1" OnItemUpdating="DetailsView1_ItemUpdating" AutoGenerateEditButton="false" AutoGenerateRows="false" GridLines="None">
        
  
       <Fields>
            
             
           <asp:TemplateField>
               
               <EditItemTemplate>
                   <asp:Button ID="btAddContact" runat="server" Text="Save Contact" CommandName="Update" />
                    
                   <table border =0 style="width:750px">
                        <tr>
                            <td  style="height: 31px" colspan=4>
                           <asp:Label id="lblInfo1" runat="server" Text="Year: "></asp:Label>                            
                           <asp:TextBox id="txtInfo2" runat="server" Width="70px"  ReadOnly="true"  BackColor="LightGray" Text='<%# Container.DataItem("Info2") %>'></asp:TextBox>     
                             <asp:Label id="lblinfo2" runat="server" Text="Name:"></asp:Label>
                            <asp:TextBox ID="txtInfo1" runat="server" Width="70px"  ReadOnly="true"  BackColor="LightGray" Text='<%# Container.DataItem("INFO1") %>'></asp:TextBox>                    
                             
                            </td>            
                        </tr>
                         
                   </table>
               </EditItemTemplate>
           </asp:TemplateField>
            
       </Fields>
   </asp:DetailsView>

updateinfo.aspx.vb

on button click
 
ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", True)

But like i said, i get error of null with window.radWindow orwindow.frameElement.radWindow

thanks for your help.

5 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 13 Dec 2012, 02:05 PM
Hi Stephane,

This report is rather strange, yet I can suggest several ideas you can try:

1) add a small timeout before closing the RadWindow, for example:
setTimeout(function(){GetRadWindow().close();},0);
you can try increasing the time if 0ms is not enough

2) if you still have null from GetRadWindow() try calling window.close(). We override the default browser close() to close the RadWindow, because it has been requested by our clients in the past. Not that such an override is not possible in IE9 and this will not work there.

3) call a function on the main page that will get a reference to the RadWIndow and close it, e.g.:
window.parent.closeTheRadWindow();


Kind regards,
Marin Bratanov
the Telerik team
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 their blog feed now.
0
Hugh
Top achievements
Rank 1
answered on 15 Nov 2014, 08:01 PM
I am having a similar problem.  I believe this was working initially, but no more.  the window.radWindow and window.frameElement are null on the child page.

appreciate any assistance.
0
Marin Bratanov
Telerik team
answered on 17 Nov 2014, 04:48 PM

Hi Steve,

We have not been able to reproduce such a problem so I cannot offer a solution to the case. What I can suggest is looking into the following:

  • My third suggestion on calling a function on the main page that will close the RadWindow (you can read more details about this approach here: http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html).
  • See if both pages have the same domain set. If they don't, RadWindow's code cannot access the iframe in order to create the backreference, so you would need to call a function from the main page in order to close the dialog, or you would need to change the document.domain property so the pages are accessible to one another (as having different domains is likely to prevent you from calling the other function as well).
  • See if there are any prior script errors in the browser and if resolving them will also resolve the current issue as well.

I hope this helps.


Regards,

Marin Bratanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
1
Ben
Top achievements
Rank 1
answered on 14 Apr 2016, 09:01 PM

I don't know if this will be helpful to anyone else but I was having a problem with a radWindow being undefined as well.The problem only occurs with a popup that's opened from the server through an ajax call. I was able to get around it by using GetRadWindowManager().getActiveWindow(). So now my GetRadWindow function looks like this

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow){
        oWindow = window.radWindow;
    } else if (window.frameElement && window.frameElement.radWindow) {
        oWindow = window.frameElement.radWindow;
    } else {
        //if the window is opened from the server, window.radWindow doesn't seem to get created
        oWindow = GetRadWindowManager().getActiveWindow();
    }
    return oWindow;
}

Mike
Top achievements
Rank 1
commented on 21 Sep 2021, 05:43 PM

Thank you Ben!!  That worked for me.
0
Marin Bratanov
Telerik team
answered on 18 Apr 2016, 07:09 AM

Hello Ben,

That can certainly be useful in certain scenarios.

I would also advise you look into using the Sys.Application.Load event for executing such scripts because this is the earliest event in which the controls objects are sure to be created. You can read more on the subject in the following article: http://docs.telerik.com/devtools/aspnet-ajax/general-information/get-client-side-reference.

Regards,

Marin Bratanov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Window
Asked by
Stephane
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Hugh
Top achievements
Rank 1
Ben
Top achievements
Rank 1
Share this question
or