[CLOSED] Error with Partial Views

Page 1 of 3 123 LastLast
  1. #1

    [CLOSED] Error with Partial Views

    Hi

    I've developed (with the extensive help of Fabricio) a new menu system using Partial Views. I'm getting occasional errors similar to this:

    Ext.net.ResourceMgr.registerIcon(["Add","Delete","DatabaseSave","ResultsetNext","Res ultsetPrevious"]);Ext.onReady(function(){Ext.net.append(Ext.net.ge tEl('PnlCenter-body'),["

    I appreciate it's not a lot to go on but it's probably going to be difficult to replicate in a simple example. Do you have any idea where I might look to find the cause?

    Thanks

    Jeff
    Last edited by fabricio.murta; Mar 10, 2016 at 2:08 PM.
  2. #2
    Can you catch this error with developer tools on your browser (ensure your ResourceManager is set to ScriptMode="Debug" SourceFormatting="True") and point "where it hurts" when the bug happens? It might point you precise file/resource and line where it happens, with stack trace and context (which class/method) it is happening.

    That would at least give some clues given we can't reproduce the issue on our side. While not ideal and maybe not even possible/allowed, if you have this running publicly somewhere and we can open the pages to see the error happening, we may be able to at least provide some clues.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi Fabricio

    The error message gets displayed like this:

    Click image for larger version. 

Name:	Error screen.png 
Views:	37 
Size:	16.6 KB 
ID:	24437

    so there doesn't seem to be a way of trapping the error? We're meeting our client this morning, so we will ask permission to allow you access to the site to see the issue for yourself.

    Thanks

    Jeff
  4. #4
    Hello Jeff!

    We are not really comfortable about accessing private applications as this can mean a number of things, that's why I asked whether it was publicly available. Maybe it is better to try and reproduce this issue in an isolated environment.

    About how to capture this, I believe you can get it using developer tools and:
    - Switch to the 'network' tab
    - Start "recording" (press the button to start capturing logging activity, it may be either a 'play' or 'rec' button in shape)
    - Issue the command to load the partial view (or update it if it loads on page load)
    - On the captured traffic, go into details and look at "response body"

    It should have a similar or same code shown, but also may have more useful information. Seems that the string is truncated on the window, or the problem might be a line break after the quotes... that will pretty much clarify by providing the raw script attempted to run.

    I believe that you'll be able to reproduce the issue in your simpler solution by iteractively adding elements of the partial view until you get the one that is breaking the response script.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hi Fabricio

    Our client has agreed to us providing you with temporary access to their prototype application. I would prefer to send you the url, user name and password by some other means rather than exposing them here. Email?

    When you gain access click on the 'Admin' menu option which will display other options down the left hand side. I haven't found a definite sequence of events which causes the error but if you click on different options after about 15 or 20 clicks it should happen. in the Client and Project options it displays a list of Clients or Projects. Clicking on one of these will display a tab panel with more details. i think you need to include clicking on the tabs to make it happen.

    Thanks

    Jeff
  6. #6
    Hi Fabricio

    I don't know if this helps or not but, using Fiddler, I have captured the script it was attempting to run when it crashed.

    HTTP/1.1 200 OK
    Cache-Control: private
    Content-Type: text/html; charset=utf-8
    Vary: Accept-Encoding
    Server: Microsoft-IIS/8.5
    X-Powered-By: ASP.NET
    Date: Wed, 24 Feb 2016 15:40:39 GMT
    Content-Length: 2513
    
    Ext.net.ResourceMgr.registerIcon(["Add","Delete"]);Ext.onReady(function(){Ext.net.append(Ext.net.getEl('PnlCenter-body'),["<script>","    var Delete = function () {","        var source = App.AccountsGridPanel;","        var records = source.getSelectionModel().getSelection();","        if (records.length == 0) {","            Ext.Msg.alert('Error!', 'Please select an element.');","        }","        else {","            Ext.net.DirectMethod.request({","                url: '/Account/Delete',","                params: {","                    selectedID: records[0].data.ID","                }","            });","        }","    };","    var edit = function (editor, e) {","        if (!(e.value === e.originalValue || (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {","            Ext.net.DirectMethod.request({","                url: '/Account/EditAccount',","                params: {","                    id: e.record.data.ID,","                    field: e.field,","                    newValue: e.value,","                    type: \"Account\"","                }","            });","        }","    };","<\/script>","  <div id=\"App.id69efd84fca6c067_Container\"></div>"].join(''));Ext.create("Ext.panel.Panel",{renderTo:"App.id69efd84fca6c067_Container",width:1600,items:[{store:{model:Ext.ClassManager.isCreated(Ext.id()) ? Ext.id() : Ext.define(Ext.id(), {extend: "Ext.data.Model", fields:[{name:"ID",type:"int"},{name:"Code"},{name:"Name"},{name:"Notes"}],idProperty:"ID" }),storeId:"Store",autoLoad:true,proxy:{type:"ajax",reader:{type:"json",rootProperty:"data"},url:"/Account/Read"}},id:"AccountsGridPanel",plugins:[{ptype:"cellediting",listeners:{edit:{fn:edit}}}],width:600,xtype:"grid",tbar:{xtype:"toolbar",items:[{id:"id92ceb98646b02067",margin:5,iconCls:"#Add",text:"Add",directEvents:{click:{fn:function(item,e){Ext.net.directRequest({cleanRequest:true,url:"/Account/Add",control:this});}}}},{margin:5,iconCls:"#Delete",text:"Delete",listeners:{click:{fn:Delete}}}]},columns:{items:[{flex:800,dataIndex:"Name",editor:new Ext.grid.CellEditor(Ext.apply({field:{id:"id94f4f433fce40067",xtype:"textfield",maxLength:100}}, {})),text:"Name"},{flex:1200,dataIndex:"Notes",editor:new Ext.grid.CellEditor(Ext.apply({field:{id:"id612ff498d9a50067",xtype:"textfield",maxLength:150}}, {})),text:"Notes"}]},multiColumnSort:false,selModel:window.App.rowSelectionModel=Ext.create("Ext.selection.RowModel",{proxyId:"rowSelectionModel",selType:"rowmodel"})}],layout:"hbox"});});
    Regards

    Jeff
  7. #7
    I have expanded the code you provided with JS Beautifier and got this:
    Ext.net.ResourceMgr.registerIcon(["Add", "Delete"]);
    Ext.onReady(function() {
        Ext.net.append(
          Ext.net.getEl('PnlCenter-body'),
          ["<script>",
           "    var Delete = function () {",
           "        var source = App.AccountsGridPanel;",
           "        var records = source.getSelectionModel().getSelection();",
           "        if (records.length == 0) {",
           "            Ext.Msg.alert('Error!', 'Please select an element.');",
           "        }",
           "        else {",
           "            Ext.net.DirectMethod.request({",
           "                url: '/Account/Delete',",
           "                params: {",
           "                    selectedID: records[0].data.ID",
           "                }",
           "            });",
           "        }",
           "    };",
           "    var edit = function (editor, e) {",
           "        if (!(e.value === e.originalValue || (Ext.isDate(e.value) && Ext.Date.isEqual(e.value, e.originalValue)))) {",
           "            Ext.net.DirectMethod.request({",
           "                url: '/Account/EditAccount',",
           "                params: {",
           "                    id: e.record.data.ID,",
           "                    field: e.field,",
           "                    newValue: e.value,",
           "                    type: \"Account\"",
           "                }",
           "            });",
           "        }",
           "    };",
           "<\/script>",
           "  <div id=\"App.id69efd84fca6c067_Container\"></div>"].join('')
        );
      
        Ext.create("Ext.panel.Panel", {
            renderTo: "App.id69efd84fca6c067_Container",
            width: 1600,
            items: [{
                store: {
                    model: Ext.ClassManager.isCreated(Ext.id()) ? Ext.id() : Ext.define(Ext.id(), {
                        extend: "Ext.data.Model",
                        fields: [{
                            name: "ID",
                            type: "int"
                        }, {
                            name: "Code"
                        }, {
                            name: "Name"
                        }, {
                            name: "Notes"
                        }],
                        idProperty: "ID"
                    }),
                    storeId: "Store",
                    autoLoad: true,
                    proxy: {
                        type: "ajax",
                        reader: {
                            type: "json",
                            rootProperty: "data"
                        },
                        url: "/Account/Read"
                    }
                },
                id: "AccountsGridPanel",
                plugins: [{
                    ptype: "cellediting",
                    listeners: {
                        edit: {
                            fn: edit
                        }
                    }
                }],
                width: 600,
                xtype: "grid",
                tbar: {
                    xtype: "toolbar",
                    items: [{
                        id: "id92ceb98646b02067",
                        margin: 5,
                        iconCls: "#Add",
                        text: "Add",
                        directEvents: {
                            click: {
                                fn: function(item, e) {
                                    Ext.net.directRequest({
                                        cleanRequest: true,
                                        url: "/Account/Add",
                                        control: this
                                    });
                                }
                            }
                        }
                    }, {
                        margin: 5,
                        iconCls: "#Delete",
                        text: "Delete",
                        listeners: {
                            click: {
                                fn: Delete
                            }
                        }
                    }]
                },
                columns: {
                    items: [{
                        flex: 800,
                        dataIndex: "Name",
                        editor: new Ext.grid.CellEditor(Ext.apply({
                            field: {
                                id: "id94f4f433fce40067",
                                xtype: "textfield",
                                maxLength: 100
                            }
                        }, {})),
                        text: "Name"
                    }, {
                        flex: 1200,
                        dataIndex: "Notes",
                        editor: new Ext.grid.CellEditor(Ext.apply({
                            field: {
                                id: "id612ff498d9a50067",
                                xtype: "textfield",
                                maxLength: 150
                            }
                        }, {})),
                        text: "Notes"
                    }]
                },
                multiColumnSort: false,
                selModel: window.App.rowSelectionModel = Ext.create("Ext.selection.RowModel", {
                    proxyId: "rowSelectionModel",
                    selType: "rowmodel"
                })
            }],
            layout: "hbox"
        });
    });
    It is hard to find some syntax or runtime errors just by reading the code, but the store creation at line 43 looked a little strange. And it can be specially true as Ext.id() makes something like Ext-35 which, when turned into a class and attempted to be referenced, may try to evaluate an expression like "Ext MINUS 35".

    A good way to catch javascript generation errors is by moving the partial view in the main view (temporarily) and building it. I've just handled another issue where the way the user was generating the components' IDs was breaking the JavaScript code (ID with hyphens and starting with numbers would make some refs like App.89af-29aa which is wrong). In your case the ID looks fine -- while your Ext.id() might be the issue!

    There, I suggested (for the sake of simplicity) as a solution just to replace what breaks. In your case something like Ext.id().replace('-','_') would do.

    Regardless of that (assuming it is not the true cause of the problem), something else on the razor syntax or code behind creating the controls is probably causing JavaScript errors on this code block, but as it is dynamically created, dev tools does not get the exact failing place. If you move the partial view inside the main view you'll probably be able to have debugger to break on the exact failing line of the generated code.

    Don't forget to enable debug code on your ResourceManager with .SourceFormatting(true).ScriptMode(Debug) during the tests (if it is not already enabled in your Web.Config).

    Well, let's hope I hit the jackpot on some of those guesses! I am pretty confident on the Ext.id() issue!
    Fabrício Murta
    Developer & Support Expert
  8. #8
    Hello again Fabricio

    I think I am a bit further on in understanding what is happening. I've found that I can replicate the issue if I click the same menu option 25 - 30 times. This menu option is clearing the content of the central panel and then loading the partial view. This involves loading several datasets from the database to support sub-views. It will do this quite correctly for 25 or so times and then fail with the message we saw. From studying the traffic in Fiddler it looks as though it's not the JavaScript that's causing the problem but one of these calls to the database. It's always the same one. Here you can see the traffic from the last couple of menu clicks:

    /Client/RenderPartialView
    /Client/GetClients?_dc=1456340434141&page=1&start=0&limit=25
    /Client/GetAccountscb?_dc=1456340434142&page=1&start=0&limit=25
    /Client/GetAccounts?_dc=1456340434143&page=1&start=0&limit=25
    /Client/GetElements?_dc=1456340434144&page=1&start=0&limit=25
    /Client/GetClientElements?_dc=1456340434148&page=1&start=0&limit=25
    /Client/GetAreas?_dc=1456340434150&page=1&start=0&limit=25
    /Client/GetLocations?_dc=1456340434152&page=1&start=0&limit=25
    /Client/GetTrackableEntities?_dc=1456340434154&page=1&start=0&limit=25
    /Client/GetRoles?_dc=1456340434155&page=1&start=0&limit=25
    /Client/RenderPartialView
    /Client/GetClients?_dc=1456340434875&page=1&start=0&limit=25
    /Client/GetAccountscb?_dc=1456340434876&page=1&start=0&limit=25
    /Client/GetAccounts?_dc=1456340434877&page=1&start=0&limit=25
    /Client/GetElements?_dc=1456340434878&page=1&start=0&limit=25
    /Client/GetClientElements?_dc=1456340434882&page=1&start=0&limit=25
    /Client/GetAreas?_dc=1456340434883&page=1&start=0&limit=25
    /Client/GetLocations?_dc=1456340434885&page=1&start=0&limit=25
    /Client/GetTrackableEntities?_dc=1456340434887&page=1&start=0&limit=25
    /Client/GetRoles?_dc=1456340434888&page=1&start=0&limit=25
    /Client/RenderPartialView
    /Client/GetClients?_dc=1456340435788&page=1&start=0&limit=25
    From Fiddler I can see that it has successfully completed the GetClients call. So presumably it is the GetAccountscb call that;s causing the problem. However, it has completed it succesfully 25 or so times before.

    Any ideas?

    Thanks

    Jeff
  9. #9
    Hello Jeff! I can think on a race condition happening there.

    Maybe you should mask the whole page (Ext.getBody().mask("Please wait, loading data...")) when the button is clicked. And then, remove the mask from the last action is run. If the different actions are run in parallel, you probably need them all to sinalize they are finished before the mask is removed.

    Probably if the tasks/actions are run in parallel one finishing after the other might trigger an error. For example, it may happen that a database request is usually fast and another action is cleaning the store always before it replies with new data. In the event it replies before the store has been reset (too fast), it can fill the store and then be erased, thus having an empty grid.

    Something similar to it might be making the problem. I am pretty confident the initial error message you sent is shown when a javaScript error happens in the action's response payload.

    Sorry, that's quite a wild guess but yet, a possibility.

    By the way, I think you can break the execution if you enable 'break on handled exceptions' in your debugger! You will probably stop by an 'Ext.error()' call with the failing script as a variable there, but you'll be able to walk back the stack trace for invaluable insight.

    Hope something of these helps!
    Fabrício Murta
    Developer & Support Expert
  10. #10
    Hi Fabricio

    Thanks for your suggestions. I'm inclined to think that adding a mask will not help because when it happens during normal use of the system there has been a significant delay between selecting the menu option and the previous request.

    One way or another I need to be able to trap the exact point at which the problem is caused. You mentioned enabling 'break on handled exceptions'. I'm using Visual Studio 2012 but I can't see that option. Could you give me a bit more detail please.

    Thanks

    Jeff
Page 1 of 3 123 LastLast

Similar Threads

  1. [CLOSED] ViewData and partial views
    By ingbabic in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 20, 2016, 12:01 PM
  2. [CLOSED] Window in Partial Views
    By Istofix in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 06, 2014, 3:18 PM
  3. [CLOSED] Javascript Error on Same IDs in multiple partial views
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Mar 05, 2014, 8:50 AM
  4. [CLOSED] [Razor] using partial views
    By machinableed in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 25, 2012, 9:40 AM
  5. Replies: 0
    Last Post: Oct 15, 2009, 6:07 AM

Posting Permissions