[CLOSED] Open window not working from included js-file

  1. #1

    [CLOSED] Open window not working from included js-file

    Hi,

    We have a problem with opening a window. If we have the JavaScript functions in the aspx-file they work great, but when we have them in a separate JavaScript-file and include the file on the page it does not work. Why is this?

    Best regards,
    Bella


    JSGlobal.js
    function openNewWindow(title, url, id, modal, width, height, renderToLevel) {
            try {
                if (width == 0)
                    width = 760;
                if (height == 0)
                    height = 500
                newWindow({ title: title, height: height, width: width, minHeight: height, minWidth: width, modal: modal, maximizable: true }, url, '', id, renderToLevel);
    
            }
            catch (e) {
                Ext.Msg.alert('Error', e.message);
            }
        }
    
        var newWindow = function (config, url, html, id, renderToLevel) {
            var renderToObject;
            var window;
    
            if (parent.parent.parent != null && renderToLevel == 3) {
                renderToObject = parent.parent.parent;
            }
            else if (parent.parent.Ext.getBody() != null && renderToLevel == 2) {
                renderToObject = parent.parent;
            }
            else if (parent.Ext.getBody() != null && renderToLevel == 1) {
                renderToObject = parent;
            }
            else {
                renderToObject = this;
            }
    
            body = renderToObject.Ext.getBody();
            window = renderToObject.Ext.getCmp(id);
            if (window != null)
                window.close();
    
            if (url != '') {
                new renderToObject.Ext.Window(renderToObject.Ext.apply({
                    renderTo: renderToObject.Ext.getBody(),
                    resizable: true,
                    height: 500,
                    width: 500,
                    frame: true,
                    padding: 5,
                    id: id,
                    collapsible: true,
                    loader: { maskMsg: 'Loading...', showMask: true, renderer: 'frame', url: url }
                }, config)).show();
            }
            else if (html != '') {
                new renderToObject.Ext.Window(renderToObject.Ext.apply({
                    renderTo: renderToObject.Ext.getBody(),
                    resizable: true,
                    height: 500,
                    width: 500,
                    frame: true,
                    padding: 5,
                    id: id,
                    collapsible: true,
                    html: html
                }, config)).show();
            }
        }
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script type="text/javascript" src="JSGlobal.js"> </script>
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Combo Boxes - Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager ID="resourceManager" runat="server">
            </ext:ResourceManager>
            <ext:Viewport ID="vp" runat="server">
                <Items>
                    <ext:Button runat="server" Text="Click">
                        <Listeners>
                            <Click Handler="openNewWindow('Test', 'Test1.aspx', 'wndBookingSelection', false,  1035, 400, 0);"></Click>
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    Last edited by Daniil; Sep 28, 2015 at 11:44 AM. Reason: [CLOSED]
  2. #2
    Hi @Bella,

    it does not work
    Please clarify what happens instead?

    The test case appears to be working for me.

    The only guess I have is a wrong path to the JSGlobal.js JavaScript file.

    Please check the resources requests in a browser. Is JSGlobal.js loaded or there is a "404 Not Found" error?
  3. #3
    Hi,

    When we open the window, the window is empty. Since we are opening the same page as we are on, we should be able to see the button.
    If we put the js functions in the aspx it works, but not when we include the js file. We know the path to the js file is right because we get the window to open, but we don't see any content.

    Best regards
    Bella
  4. #4
    Is the problem inside Test1.aspx maybe?
  5. #5
    Hi
    Here is a full code example including Test1.aspx, the important thing to produce the error is that the openNewWindow and the newWindow functions is in a separate .js -file that you include from the aspx-file.
    We have tested this in both Chrome, Firefox and Internet Explorer, what happens is that the window gets created and opened, and the Page_load get called in the Test1.aspx, but it doesn't render in the iframe in the window. We have the feeling that the content renders to another object, and not the window as its supposed to.
    We run Ext version 3.2.1

    Best regards
    Bella

    JSGlobal.js
    function openNewWindow(title, url, id, modal, width, height, renderToLevel) {
            try {
                if (width == 0)
                    width = 760;
                if (height == 0)
                    height = 500
                newWindow({ title: title, height: height, width: width, minHeight: height, minWidth: width, modal: modal, maximizable: true }, url, '', id, renderToLevel);
    
            }
            catch (e) {
                Ext.Msg.alert('Error', e.message);
            }
        }
    
        var newWindow = function (config, url, html, id, renderToLevel) {
            var renderToObject;
            var window;
    
            if (parent.parent.parent != null && renderToLevel == 3) {
                renderToObject = parent.parent.parent;
            }
            else if (parent.parent.Ext.getBody() != null && renderToLevel == 2) {
                renderToObject = parent.parent;
            }
            else if (parent.Ext.getBody() != null && renderToLevel == 1) {
                renderToObject = parent;
            }
            else {
                renderToObject = this;
            }
    
            body = renderToObject.Ext.getBody();
            window = renderToObject.Ext.getCmp(id);
            if (window != null)
                window.close();
    
            if (url != '') {
                new renderToObject.Ext.Window(renderToObject.Ext.apply({
                    renderTo: renderToObject.Ext.getBody(),
                    resizable: true,
                    height: 500,
                    width: 500,
                    frame: true,
                    padding: 5,
                    id: id,
                    collapsible: true,
                    loader: { maskMsg: 'Loading...', showMask: true, renderer: 'frame', url: url }
                }, config)).show();
            }
            else if (html != '') {
                new renderToObject.Ext.Window(renderToObject.Ext.apply({
                    renderTo: renderToObject.Ext.getBody(),
                    resizable: true,
                    height: 500,
                    width: 500,
                    frame: true,
                    padding: 5,
                    id: id,
                    collapsible: true,
                    html: html
                }, config)).show();
            }
        }
    Main.aspx
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script type="text/javascript" src="JSGlobal.js"> </script>
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Combo Boxes - Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager ID="resourceManager" runat="server">
            </ext:ResourceManager>
            <ext:Viewport ID="vp" runat="server">
                <Items>
                    <ext:Button runat="server" Text="Click">
                        <Listeners>
                            <Click Handler="openNewWindow('Test', 'Test1.aspx', 'wndBookingSelection', false,  1035, 400, 0);"></Click>
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    Test1.aspx
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Test1</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager ID="resourceManager" runat="server">
            </ext:ResourceManager>
            <ext:Viewport ID="vp" runat="server">
                <Items>
                    <ext:Label runat="server" Text="Label"></ext:Label>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    Last edited by Bella; Sep 28, 2015 at 9:24 AM.
  6. #6
    Thank you for the full test case. Though, I still cannot reproduce. The child page renders well for me. I see the "Label" text.

    I don't quite have any ideas what might be wrong on your side. Do you see JavaScript error in a browser's console? Could you, please, inspect the iframe HTML element and see what is there?

    I am testing with a freshly created project. My steps are:

    1. Create an Empty ASP.NET Web Application
    2. Install-Package Ext.NET
    3. Put the Main.aspx, Test1.aspx and JSGlobal.js files into the project
    4. Run Main.aspx
    5. Click the button

    Are you testing with a new basic project or inside your existing project? If the second, please try to test with a freshly created project following my steps. Maybe, there is something in your existing project.
  7. #7
    Thank you!

    We had made a mistake in the js-file, now it works great.

Similar Threads

  1. Replies: 1
    Last Post: Sep 02, 2015, 2:54 AM
  2. Replies: 2
    Last Post: Jul 12, 2013, 4:45 PM
  3. Download and open a file in a separate window
    By unaltro2 in forum 1.x Help
    Replies: 2
    Last Post: Jan 21, 2010, 12:55 PM
  4. [CLOSED] Open file from grid
    By methode in forum 1.x Premium Help
    Replies: 4
    Last Post: Dec 29, 2008, 10:17 AM
  5. Replies: 3
    Last Post: Nov 27, 2008, 1:52 PM

Posting Permissions