Calling Direct Method from client side .js

  1. #1

    Calling Direct Method from client side .js

    Hello again,

    sorry for persisting on the subject.
    In our current Ext.Net 3 architecture we rely heavily on calling Direct Methods from client JS functions.
    I appreciate the Direct Event example provided above, but what interest us is what is the equivalent of adding a [Direct Method] attribute to a function in order to make it accessible in the App.Direct client side namespace?

    We basically use Web Forms in its most basic format, executing ASP.NET code only in the Page_Load method. Everything else happens in [Direct Method] functions. So, essentially, we do not use [Direct Events] which require binding to specific DOM Components.
    In a similar approach, can we have code execute server side without having to use a Direct Event but rather call a Direct Method as per below?

    Client Side:
    function do_register() {
    
      App.direct.Register(
                          {
                            success: function (result) {
                              if (result) {
                                close_register();
                              }
                            },
                            eventMask: { showMask: true, msg: App.WAIT },
                            failure: function (errorMsg) { Ext.Msg.alert(App.PROBLEM, errorMsg); }
                          });
    }

    Server side:

    [DirectMethod]
      public bool Register()
      {
         //some code
         return false;
      }
    Thank you very much for your time.
    Kind regards.
    Last edited by AnFil; Nov 01, 2020 at 5:51 PM. Reason: Typo
  2. #2
    Hello @AnFil!

    I have moved your post to a dedicated thread in the 7.x classic forums, hope it's not a problem, as your inquire would be just hidden somewhere or just that it was going a little away from the initial thread's topic.

    Anyway, you had it almost done with title and all, so I just moved it. :-)

    To use direct methods in Ext.NET 7, you should make similar annotations to the class and methods; in a simplistic approach with a direct method that just sleeps for 8 seconds on a default Index RazorPage, you'd have its controller/model code like this:

    [DirectModel]
    public class IndexModel : PageModel
    {
        public void OnGet()
        {
    
        }
    
        [Direct]
        public IActionResult OnPostSomeDirectMethod()
        {
            System.Threading.Thread.Sleep(8000);
            return this.Direct();
        }
    }
    Then in the index page you could call it anytime from client side by App.direct.SomeDirectMethod().

    From this point you can go ahead and experiment with passing parameters, returning code, changing components' state.

    Notice outside of WebForms world, we won't have a this.MyComponentsId reference from code behind anymore. To get a handle from a component given its ID, it is a similar approach to Ext.NET MVC: this.GetCmp<ComponentType>("MyComponentsId")

    We will add an example using direct methods to Examples explorer the next time it is refereshed, it will be equivalent to the Version 5's Events > Direct Events > Duration Messages (it does have one case within it using a direct method and not only direct events).

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello Fabricio,

    This helps clear things up a lot.
    I will experiment and see how far i get with porting out ExtNet3 code :)

    Thank you very much for your help.
  4. #4
    We are working on an enhancement that will enable returning a value from the Direct Method.

    [Direct]
    public IActionResult OnPostRegister
    {
        return this.Direct(false);
    }
    On the client, you would call using the same code as you provided above; `App.direct.Register(...)`.

    We're hoping this will be included in the next Ext.NET Classic release (7.2.0).
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 3
    Last Post: Aug 03, 2015, 4:59 PM
  2. Replies: 0
    Last Post: Jun 07, 2013, 11:24 AM
  3. Replies: 0
    Last Post: Mar 08, 2012, 9:45 AM
  4. Success function in calling Direct Method..help!
    By Aleksa007 in forum 1.x Help
    Replies: 2
    Last Post: Jul 26, 2011, 4:36 PM
  5. Replies: 2
    Last Post: Apr 27, 2011, 2:58 PM

Posting Permissions