Problem closing RadWindow using javascript

4 posts, 0 answers
  1. Condorito
    Condorito avatar
    38 posts
    Member since:
    Mar 2009

    Posted 06 Apr 2009 Link to this post

    Hi,

    I have a window defined inside a user control:

    <telerik:RadScriptBlock ID="rsbMain" runat="server"
             <script type="text/javascript"
                        //<![CDATA[
                            function OpenTrackAndTraceDialogDialog(Company,DocNum)
                         { 
                                var oWnd = $find('<%= radTrackAndTraceDialog.ClientID %>');
                                oWnd.setUrl("dialogs/dlgTrackAndTraceDialog.aspx?Company=" + Company + "&DocNum=" + DocNum);
                               oWnd.maximize();
                                oWnd.show();
                            }
                        //]]> 
                        </script> 
                 
             </telerik:RadScriptBlock> 
                     
            <telerik:RadWindowManager ID="rwwDialogs" runat="server" Skin="Office2007" Style="z-index:7100"
        <Windows> 
            <telerik:RadWindow ID="radTrackAndTraceDialog" runat="server"  
                ShowContentDuringLoad="false"  
                AutoSize="true" 
                Modal="false" 
                VisibleStatusbar="false" 
                ReloadOnShow="false" 
                Behaviors="Close, Reload, Move, Maximize" 
                height="500px" 
                width="500px" 
                 
                > 
            </telerik:RadWindow> 
        </Windows> 
    </telerik:RadWindowManager> 

    The OpenTrackAndTraceDialogDialog is called from inside an aspx page which contains the user control that contains the above code.

    the dlgTrackAndTraceDialog.aspx has the logic to display the content of the dialog:  it calls a web service and if the web service returns a URL, it opens up a pop-up by adding an onload event to the body HTML tag, server-side.  It then is supposed to close the RadWindow after the real browser pop-up is displayed.  Below is the code I use to accomplish this, located inside the dlgTrackAndTraceDialog.aspx:

      <script language="JavaScript" type="text/javascript"
        
       function GetRadWindow() 
        { 
         var oWindow = null
         if (window.radWindow) 
            oWindow = window.radWindow;      
         else if (window.frameElement.radWindow) 
           oWindow = window.frameElement.radWindow; 
         return oWindow; 
       } 
        
         function closeCallingWindow() 
        { 
        var oWindow = GetRadWindow(); 
        //alert(oWindow); 
        oWindow.close(); 
           
          
        } 
        
        function popUp(URL) { 
        day = new Date(); 
        id = day.getTime(); 
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=550,height=500,left = 600,top = 300');"); 
        } 
        </script> 

    The popUp function is triggered inside the onload event of the body tag of the dlgTrackAndTraceDialog.aspx  page, and I insert it as an attribute during server side if I get a valid URL from the web service call.

    Everything works great....except that the RadWindow won't close and even if I click on the close button, it still won't close.  I can maximize, and minimize the window though, and I don't get any error messages.

    What am I doing wrong?  Thank you in advance for your help.

  2. Condorito
    Condorito avatar
    38 posts
    Member since:
    Mar 2009

    Posted 06 Apr 2009 Link to this post

    Forgot to mention, the reason why I'm opening up the external URL as a pop-up and not inside the Telerik Window is because the website detects that it's inside an HTML object so it redirects the browser to itself so it's no longer inside the dialog.
  3. Condorito
    Condorito avatar
    38 posts
    Member since:
    Mar 2009

    Posted 06 Apr 2009 Link to this post

    Ok figured it out...had to use an Inject Script inside an ASP.NET label that calls the close window function.  It now behaves as it should.
  4. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 08 Apr 2009 Link to this post

    Hi Juan,

    It is good to know that you found a solution. I would suggest however to consider changing the approach - using a label to output JavaScript is not a recommended practice in ASP.NET AJAX environment. In such scenario I suggest to use for example the RegisterStartupScript method, or if you are using Ajax - the RegisterStartupScript() method of the ScriptManager.
    More information on the subject is available here:
    http://www.telerik.com/support/kb/aspnet-ajax/window/calling-radalert-from-codebehind.aspx



    Regards,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top