[CLOSED] DirectMethod not working - page lifecycle is fired

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] DirectMethod not working - page lifecycle is fired

    From the examples DirectMehtod Overview
    When calling a public server-side Method, but default the complete Page lifecycle is executed and the Method has access to all web controls on the Page.
    With a 'static' [DirectMethod] the Page lifecycle is not executed and access to the Page WebControls are not possible. This reduces the processing overhead and optimizes performance.
    I have the following server-side code
            [DirectMethod(ClientProxy=ClientProxy.Ignore)]
            public static int GetRegistrationsCount(int personId)
            {
                return 55; // return const for testing purposes
            }
    and the following client-side javascript:
    function GetRegistrationsCount() {
            var regCount = -1;
            Ext.net.DirectMethod.request("GetRegistrationsCount", 
            {
                success: function(result) { debugger;  regCount = parseInt(result, 10); },
                params: { personId: globalPersonId }
            });
        }
    but when I call GetRegistrationsCount from a client-side pushbutton event handler:
    <Click Handler="GetRegistrationsCount();" />
    the entire page content is rendered and the directmethod is never called.

    Am I missing something or doing something wrong? Or is the Ext.NET demos documentation incorrect?

    TIA
    Last edited by Daniil; Mar 07, 2011 at 9:19 PM. Reason: Marked as [CLOSED]. No more information was provided.
  2. #2
    Hi,

    1. Please note that static direct methods are supported inside page only
    2. If you call a static method manually (without proxy method) then you have to define static specifier
    Ext.net.DirectMethod.request("GetRegistrationsCount", 
    {
        specifier:"static"     
    });
  3. #3
    Hi,

    Is there AutoPostBack="true" for Button? If so, please remove it.
    Last edited by geoffrey.mcgill; Dec 04, 2019 at 8:34 PM.
  4. #4
    Quote Originally Posted by Vladimir View Post
    Hi,

    1. Please note that static direct methods are supported inside page only
    2. If you call a static method manually (without proxy method) then you have to define static specifier
    Ext.net.DirectMethod.request("GetRegistrationsCount", 
    {
        specifier:"static"     
    });
    so you mean the direct method cannot be defined in the code-behind page? I don't understand how that makes a difference.
  5. #5
    Quote Originally Posted by Daniil View Post
    Hi,

    Is there AutoPostBack="true" for Button? If so, please remove it.
    No there isn't an Autopostback but that was something I hadn't thought of so thanks for pointing it out.
  6. #6
    Hi,

    so you mean the direct method cannot be defined in the code-behind page? I don't understand how that makes a difference.
    What you mean? DirectMethod can be defined in the code behind only. When i wrote "static direct methods are supported inside page only" I meant that static direct method can be defined inside page class only, static direct methods inside user control are not supported (instance direct methods only can be defined inside user control)
  7. #7
    As a note for future reference... the original question probably could have been solved in one single response if a full .aspx code sample was provided demonstrating how the page and relationship between the DirectMethod was configured. If the proper amount of information was provided in the initial forum post this should have been a simple and quick question to answer.

    The first response by Vladimir was posted within 11 minutes and it should have ended there. We're now 16+ hours into this support thread and it's unclear whether this thread has been solved. At this point we're still left guessing what/where the problem may be located.

    It would be best to take the time to review the Forum Guidelines for posting new topics.

    Providing an adequate amount of information from the start will help ensure you get the absolute fastest and most accurate response we can give. If not enough information is provided, the unfortunate result is an ineffective use of everyones time.

    http://forums.ext.net/showthread.php...ing-New-Topics
    Last edited by geoffrey.mcgill; Feb 28, 2011 at 8:21 PM.
    Geoffrey McGill
    Founder
  8. #8
    Quote Originally Posted by geoffrey.mcgill View Post
    As a note for future reference... the original question probably could have been solved in one single response if a full .aspx code sample was provided demonstrating how the page and relationship between the DirectMethod was configured. If the proper amount of information was provided in the initial forum post this should have been a simple and quick question to answer.
    Fair enough. The page code and code behind is over 2000 lines of code in total so I didn't think anyone would want to trawl through that, hence I didn't post the code.

    However, I've managed to resolve the issue myself after creating a very simple page with the same DirectMethod call and found that my original page has
    Ext.lib.Ajax.defaultPostHeader = 'application/json'
    in the DocumentReady handler of the ResourceManager - this was added for the JsonReaders used in my stores.

    Inspecting the response content using Fiddler showed me the error message:

    {success:false,errorMessage:"System.Exception: No methodName has been set in the configuration.\r\n   at Ext.Net.DirectRequestModule.ProcessRequest(HttpApplication app, HttpRequest request)"}
    Setting the default post header to form-urlencoded before calling the DirectMethod solved the problem:

        function GetRegistrationsCount() {
            Ext.lib.Ajax.defaultPostHeader = 'application/x-www-form-urlencoded';
            debugger;
            var regCount = -1;
            Ext.net.DirectMethods.GetRegistrationsCount(globalPersonId,
            {
                success: function(result) { debugger; regCount = parseInt(result, 10); }
            });
            Ext.lib.Ajax.defaultPostHeader = 'application/json';
        }
    But I'm now wondering if I need to set the request content type to application/json because this page was originally created with a very early version of Coolite and calls to Ext.Ajax.request() would fail without that content type assignment. Unless the request() method no longer requires the request header to be explicitly set to JSON?

    The lesson learned here then is that a page containing both DirectMethods and calls to Ext.Ajax.request must have the request content type set appropriately.
  9. #9
    After revisiting my original code's calls to Ext.Ajax.request() I'm now setting the jsonData config option instead of param so no need to do this
    Ext.lib.Ajax.defaultPostHeader = 'application/json'
    any longer. I don't think the jsonData config option was available in ExtJS when I originally wrote that code a few years ago.
  10. #10
    Hi,

    If you need to pass direct method params with json request then use json=true option
    https://examples1.ext.net/#/Events/D...ds/WebService/

    I am not sure why do you set json for the request header when you call page's direct method but it can broke request. Please use json option for targets are expected it only (like, json web service)
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: Mar 19, 2012, 3:08 PM
  2. DirectMethod success and failure not working
    By mtrutledge in forum 1.x Help
    Replies: 3
    Last Post: Mar 14, 2012, 1:08 PM
  3. [CLOSED] DirectMethod with empty namespace not working
    By sailendra in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 14, 2012, 9:21 AM
  4. [CLOSED] DirectMethod: UserControl in a Layer not working
    By nhg_itd in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 20, 2012, 2:12 AM
  5. simple DirectMethod call not working?
    By phinoppix in forum 1.x Help
    Replies: 2
    Last Post: Jul 05, 2011, 12:12 PM

Posting Permissions