[CLOSED] resourcemanager onload doesnt work

  1. #1

    [CLOSED] resourcemanager onload doesnt work

    Hi
    this is a simple test case
        <ext-resourceManager onload="onLoad();" />
    It is really important since <body onload="onLoad();"> doesnt work since that body onload may activate before all EXT components are rendered giving null values. We rely on the resource manager to tell us when EXT is done.

    However, in this case, the onLoad isnt hit. when i moved the onload function to body, it was hit just fine.

    please assist. What am i doing wrong?
    Thanks
    /Z
  2. #2
    Hello @Z!

    You're not really doing it wrong. I see intellisense does suggest us to use this onload in the ext-resourceManager markup. But it is not really supported (as many other HTML events it suggests), because it is a TagHelper for Ext.NET.

    Well, details aside, what you need is something we used even in Ext.NET 5, client-side Ext.onReady(). What's counter-intuitive here though, is that you can't call it in a script block within the page's <head /> block. You'd need to add a script block into the <body /> (or somewhere within it). This would ensure the Ext client-side namespace is available (Ext.NET resources included) when that part of the document is parsed. Here's an example using it:

    @page
    @model SampleProject.SamplePageModel
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>
            Run client side code after load - Ext.NET Examples
        </title>
    </head>
    <body>
        <script type="text/javascript">
            Ext.onReady(function() {
                App.Label1.setHtml("Value after load");
            })
        </script>
    
        <ext-label id="Label1" html="Value before load" />
    </body>
    </html>
    The result then would be the label will read after "Value after load" when the page load completes.

    Another alternative would be to just set Ext.NET to run your client-side code on load -- from the OnGet() code behind function. For this we'll need also the code behind code to show the example. From this CSHTML markup page:

    @page
    @model SampleProject.SamplePageModel
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>
            Run client side code after load - Ext.NET Examples
        </title>
        <script type="text/javascript">
            function onLoadHandler(extra) {
                App.Label1.setHtml("Value after load:" + extra);
            }
        </script>
    </head>
    <body>
    
        <ext-label id="Label1" html="Value before load" />
    </body>
    </html>
    The OnGet() implementation in page model:
    public void OnGet()
    {
        //this.X().AddScript("onLoadHandler('my argument');");
        this.X().Call("onLoadHandler", "my argument");
    }
    So, from this you can derive a few alternatives in doing so. You can even set the onLoadHandler() function in the second example to call Ext.onReady() to ensure your code will only be triggered after Ext.NET's renderings are done.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Add record into store of combo box doesnt work first time
    By glenh in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 26, 2015, 6:13 AM
  2. Replies: 5
    Last Post: Mar 28, 2014, 1:11 AM
  3. Replies: 9
    Last Post: Feb 14, 2013, 2:55 PM
  4. Replies: 0
    Last Post: May 08, 2012, 6:15 AM
  5. AJAX Method doesnt work
    By hbaraza in forum 1.x Help
    Replies: 1
    Last Post: Jan 15, 2009, 11:20 AM

Posting Permissions