Show a load mask with a DirectMethod call

  1. #1

    Show a load mask with a DirectMethod call

    Hi All, Here is a Button setup from codebehind as well as the directmethod.

    //-----------Setup the event handler on the button----------------------
    buttonObject.Listeners.Click.Handler = "#{DirectMethods}.DoSomething();";
    //----------End

    //---------------The direct method body------------
    [DirectMethod]
        public void DoSomething()
        {
            MaskConfig cfg = new MaskConfig();
            cfg.Msg = "Loading group data...";
            cfg.El = "Ext.getBody()";
            X.Mask.Show(cfg);
            Thread.Sleep(1000); //simulate some work
            X.Mask.Hide();        
        }
    //---------END

    But for some reason it just doesnt work.

    Am i doing the right thing ?
    Last edited by geoffrey.mcgill; Apr 21, 2012 at 4:47 PM. Reason: please use [CODE] tags
  2. #2
    Hello,

    If you inspect the Response from your [DirectMethod] with a tool such as Firebug for Firefox, you should see that both the call to "show" the mask and to "hide" the mask as sent in the same request. The mask is shown, then immediately hidden... after the 1000ms delay server-side.

    There is only one response from a DirectMethod, and that is the final response. Any Methods you call are buffered into one compiled script, which is then sent to the browser (client) once the DirectMethod is finished running. If you Sleep the thread (or any delay) between method calls, those methods are just sent to the buffer and everything waits for the last process to finish.

    You should show the Mask before calling the [DirectMethod], then call X.Mask.Hide() once your long running server-side task is complete. The following sample demonstrates a full scenario.

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" TagPrefix="ext" Namespace="Ext.Net" %>
    
    
    <script runat="server">
        [DirectMethod(Namespace = "CompanyX")]
        public void DoSomething()
        {
            System.Threading.Thread.Sleep(3000);
            X.Mask.Hide();
        }
    </script>
    
    
    <html>
    <head>
        <title>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
         
        <ext:Button runat="server" Text="Submit">
            <Listeners>
                <Click Handler="Ext.net.Mask.show({ msg : 'Loading group data...' }); CompanyX.DoSomething();" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3

    Worked like a charm

    Quote Originally Posted by geoffrey.mcgill View Post
    Hello,

    If you inspect the Response from your [DirectMethod] with a tool such as Firebug for Firefox, you should see that both the call to "show" the mask and to "hide" the mask as sent in the same request. The mask is shown, then immediately hidden... after the 1000ms delay server-side.

    There is only one response from a DirectMethod, and that is the final response. Any Methods you call are buffered into one compiled script, which is then sent to the browser (client) once the DirectMethod is finished running. If you Sleep the thread (or any delay) between method calls, those methods are just sent to the buffer and everything waits for the last process to finish.

    You should show the Mask before calling the [DirectMethod], then call X.Mask.Hide() once your long running server-side task is complete. The following sample demonstrates a full scenario.

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" TagPrefix="ext" Namespace="Ext.Net" %>
    
    
    <script runat="server">
        [DirectMethod(Namespace = "CompanyX")]
        public void DoSomething()
        {
            System.Threading.Thread.Sleep(3000);
            X.Mask.Hide();
        }
    </script>
    
    
    <html>
    <head>
        <title>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
         
        <ext:Button runat="server" Text="Submit">
            <Listeners>
                <Click Handler="Ext.net.Mask.show({ msg : 'Loading group data...' }); CompanyX.DoSomething();" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Hope this helps.
    Thanks . That was a big help.
    The quick response is most appreciated.

    One question though : I am quite new to sencha (extjs) and its wrappers like ext.net and gwt. I have seen some developers who directly write extjs based javascript and include it in the aspx page as a <script> . And i also see some developers that use ext.net or gwt.

    The (newbie) quiestion would be : which of the above is the right way. Are both equally good or does one have an edge over the other ?

    Thanks again for the quick reply

    Regards

    Ashwin

Similar Threads

  1. [CLOSED] RowExpander show mask on expand event to load data
    By bakardi in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 02, 2012, 3:02 PM
  2. [CLOSED] help with DirectMethod mask
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 04, 2011, 8:59 PM
  3. Call DirectMethod from a TreePanel
    By khadga in forum 1.x Help
    Replies: 3
    Last Post: Jan 10, 2011, 5:56 PM
  4. how to call DirectMethod from grid
    By harshad.jadhav in forum 1.x Help
    Replies: 2
    Last Post: Jul 10, 2010, 8:58 AM
  5. Replies: 0
    Last Post: May 21, 2009, 2:02 PM

Tags for this Thread

Posting Permissions