[CLOSED] Call init script manually

  1. #1

    [CLOSED] Call init script manually

    Is it possible to have the resource manager generate a callable init script so that I can load other javascript files first. I would like to us a JS loader to control the loading of the ext and ext.net resources but since the resource manager controls when the init script is executed I can not.
    Last edited by Daniil; Sep 15, 2012 at 3:55 PM. Reason: [CLOSED]
  2. #2
    Hi,

    The Ext.onReady() script waits loading of all resources. So, please clarify the requirement.

    To manage Ext.NET resources manually you can set the ResourceManager RenderScripts and RenderStyles options to None or File and register these resources manually.
  3. #3
    Hi Daniil,

    If you set scripts to none and try to use a script loader like http://labjs.com to load the ext and ext.net js files it will not work because the init script that the resource manager creates is in the head tag and executes immediately. You will get the error, Ext is not defined. My question is can that init script be wrapped in a function that I can call once I know all the scripts are load and I am ready to init the page?

    Thanks,

    Frank
  4. #4
    Quote Originally Posted by fpw2377 View Post
    Is it possible to have the resource manager generate a callable init script so that I can load other javascript files first. I would like to us a JS loader to control the loading of the ext and ext.net resources but since the resource manager controls when the init script is executed I can not.
    Good question. I'm taking a look at this.
    Geoffrey McGill
    Founder
  5. #5
    Thanks for clarification. Now the requirement is clear for me.

    Agreed with @Geoffrey, it is an interesting issue. I will look into as well.
  6. #6
    Thanks to both of you. The only reason I am going down this path is to better support the Ipad/webkit devices. We use viewports for a lot of our pages and the results are not good so I am overriding the view extjs/extnetjs code to allow for fixed widths but had a really hard time getting everything to load in the right order. I am currently appending my js to the ext.net all js file to get it to work but if I could use a loader that would make life much easier!

    Frank
  7. #7
    Hi Frank,

    We are working on a new feature to enable customization of when the initialization script is fired, but...

    ... the feature can only be included in the 2.x build. The feature will be included in the upcoming v2.1 release.

    Unfortunately, we cannot add to the v1.x branch.

    For Ext.NET 1.x, I would try overriding the Ext.onReady function. This is generally a bad idea, although for your scenario it could provide an acceptable work-around.

    Example

    Ext._onReady = Ext.onReady;
    
    Ext.onReady = function () {
        // do something here...
    
        // call the original Ext.onReady function when ready to initialize.
        Ext._onReady(arguments);
    };
    We'll post an update once the functionality has been committed to the 2.x /trunk/.
    Geoffrey McGill
    Founder
  8. #8
    Vladimir implemented this feature in Ext.NET v2.

    Now you can configure the ResourceManager App property.

    There are the two options available.

    • AutoInit

    true (default) - the initialization Ext.onReady script will be executed automatically.
    false - the initialization Ext.onReady script will be deferred. This script will be moved to the initialization "App.initFn" function which you can call manually when needed.

    Please note that The "App" is the default Namespace which can be changed setting the ResourceManager Namespace property or the namespace option of the Ext.NET section in Web.config.

    • InitFnName

    The name of the initialization function. Defaults to "initFn".

    Thank you for the great suggestion, Frank!


    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "test1", "test2", "test3" },
                    new object[] { "test4", "test5", "test6" },
                    new object[] { "test7", "test8", "test9" },
                };
                store.DataBind();
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server">
            <App AutoInit="false" />
        </ext:ResourceManager>
    
        <input type="button" value="Run" onclick="App.initFn();" />
    
        <ext:GridPanel ID="GridPanel1" runat="server">
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="test1" />
                                <ext:ModelField Name="test2" />
                                <ext:ModelField Name="test3" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column runat="server" Text="Test1" DataIndex="test1" />
                    <ext:Column runat="server" Text="Test2" DataIndex="test2" />
                    <ext:Column runat="server" Text="Test3" DataIndex="test3" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </body>
    </html>

Similar Threads

  1. Init script in browser cache
    By moldeveloper in forum Feature Requests
    Replies: 1
    Last Post: Jun 08, 2012, 9:43 AM
  2. [CLOSED] Weird error with init script being called twice from IE
    By PhilG in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 13, 2012, 10:10 AM
  3. [CLOSED] How to include Ext JS Script manually
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 23, 2010, 12:24 PM
  4. Replies: 4
    Last Post: Jul 09, 2009, 3:47 PM
  5. Replies: 2
    Last Post: Jan 27, 2009, 3:56 PM

Tags for this Thread

Posting Permissions