[CLOSED] Static DirectMethod

Page 1 of 3 123 LastLast
  1. #1

    [CLOSED] Static DirectMethod

    Hi,

    I have a static directmethod (using static for the first time).

    I get an error when I call it. Following is the error. Using the latest from SVN.

    {success:false,errorMessage:"System.Exception: The static DirectMethod '' has not been defined.\r\n at Ext.Net.DirectRequestModule.ProcessRequest(HttpApplication app, HttpRequest request) in C:\\inetpub\\Projects\\Ext.Net\\1.0.0\\Ext.Net\\Core\\DirectRequestModule.cs:line 118"}
    The following is the code :

    [DirectMethod]
    public static bool delete(Decimal aptId)
    {
    
        return DeleteApt(aptId);
       
    }
  2. #2

    RE: [CLOSED] Static DirectMethod

    Hi Amit,

    Your static [DirectMethod] appears to be configured properly.


    Geoffrey McGill
    Founder
  3. #3

    RE: [CLOSED] Static DirectMethod

    If I change it to non static method... It works... What do you think it could be....

  4. #4

    RE: [CLOSED] Static DirectMethod

    Hi,

    1. DirectMethod cannot has the 'delete' name because such name conflicts with 'delete' javascript keyword (at least in IE)
    2. I think you have cache issue. Just if you test program in Release mode than we use cache (to prevent reflection overhead). If you add DirectMethod during development then it is better to use Debug mode (in this case the cache is not used). In Release mode you have to reset IIS to drop the cache

    Here is my test case which works fine
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        
        <script runat="server">
            [DirectMethod]
            public static bool Delete(Decimal aptId)
            {
                return true;
            }
        </script>
    </head>
    <body>    
            <form id="form1" runat="server">
                <ext:ResourceManager runat="server" />
                
                <ext:Button ID="Button1" runat="server" Text="Call method">
                   <Listeners>
                        <Click Handler="#{DirectMethods}.Delete(0, {success:function(){alert('success');}, failure:function(){alert('failure');}});" />
                   </Listeners>
                </ext:Button>
                
               
            </form>
    </body>
    </html>
  5. #5

    RE: [CLOSED] Static DirectMethod

    Hi Vlad...I am not using the Delete name... I am using deleteApt. So I think that should not be a problem.


    As for cache... I change it to a normal method... and it properly after rebuild...and when I change to static it does'nt.


    I will still try your sol'n and and update this post.


    Thanks,


  6. #6

    RE: [CLOSED] Static DirectMethod

    I am also facing the same issue. The attached code demonstrates this.
  7. #7

    RE: [CLOSED] Static DirectMethod

    Thinking about this problem passively, I think the issue does make sense. The reproducible code I attached above basically has a static DirectMethod in a UserControl, that is registered on the main .aspx page.

    Now knowing that Static DirectMethods does neither postback ViewState, nor does they load server-side controls on the server, probably what is happening is, that on the server-side in the Ajax call, the Ext.Net framework does not load up the UserControl that hosts the static AjaxMethod and therefore throws the error as stated above in the opening post of the thread.


    I checked the Ext.net.DirectMethods namespace in the javascript. It has the static Ajax method proxy inside its parent UserControl's alias. This means the method was recognized and registered properly on the initial Page Load (GET) request.
    But the framework fails to relocate the method again in the Ajax call, as it does not load up controls for static methods.


    I had raised this issue much before also:
    http://forums.ext.net/showthread.php...15604-7-1.aspx


    However, I always thought that it was a conflict of DNN with Coolite. And never realized on that thread also, that there also, the issue was being caused by static Ajax Methods (needless to mention inside Usercontrols, because all DNN modulesa re inherently a collection of UserControls by design). I have successfully used non-static AjaxMethods in DNN usercontrols also, and so the issue in the above mentioned thread is also existent for static Ajax Methods only.


    Moving forward, I think this might be a major feature request from the Ext.Net team (I am mixing Coolite/Ext.Net in this post, because the issues and threads being discussed span both the brand timeframes).


    And this should not be too difficult also. If a static Ajax Method is in a UserControl, the Ext.Net framework can just register this as a flag, together with the server-location of the UserControl's .ascx file.


    Then in the Ajax call, load the UserControl, and just invoke the static AjaxMethod on it (without needing to add the loaded UserControl to any control collection). As the method is static, there is no question of life-cycle events, or loading ViewStates, and so there is no need of adding the loaded UserControl to control collection of some parent.


    I think the last piece in this puzzle should be, how do you access the LoadControl method in a static context (needed for accessing the UserControl). Although there can be quick-and -dirty hacks for this, but another approach could be to just instantize the UserControl's class directly through its assembly in the Ajax call. What I mean is,


    Object o = new UserControl();


    Again for this to be done, the framework would need to register the UserControl's run-time assembly generated by ASP.NET during the initial page load, and then create an instance of the UserControl from that assembly, after which it should be straight-forward to invoke the static AjaxMethod on it.
  8. #8

    RE: [CLOSED] Static DirectMethod

    Well, after some more thought, I think even the approach in the above post is not required (basically because we do not need to instantize the control for the static DirectMethod), so there is no need for LoadControl, or even new Control().

    Instead we can use any of the following:
    1) Register the UserControl's assembly in the initial GET request as:
    usercontrol1.GetType().FullPath
    In the Ajax call, just load the assembly from the path, then load the class from the assembly, and call the static Ajax Method on it.


    2) An even more quick approach would be to just maintain a reference to:
    Usercontrol1.GetType()
    somewhere (in the cache or whatever), and then just invoke the method on it (using Reflection's InvokeMethod) in the Ajax call.
  9. #9

    RE: [CLOSED] Static DirectMethod

    I think one thing worth watching out for any solution built around any of the suggestions above would be the modification of UserControl or its code-behind class in a WSP project model (or only the UserControl in WAP).

    I have not researched the (seemingly random) names generated by ASP.NET compiler on the fly for UserControls (e.g. App_Web_xxxxx) assemblies. If these names are guaranteed to be consistent across modifications of UserControls, then perhaps the option of storing the FullPath of the assembly of the UserControl could be better. If not, we would need to look for some other way.


    In any case, we will probably need to put a FileSystemWatcher on the files involved with the UserControl (.ascx and code-behind as applicable), and need to raise an error if the file was modified.


    As I was writing this, I had another idea, which would eliminate any plumbing as described above, the System.Web.Compilation namespace.


    How about the System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath method? This method together with other static methods in the same class (BuildManager) should provide everything that one might need to handle static UserControl ajax calls without worrying for File modification times or whatever.
  10. #10

    RE: [CLOSED] Static DirectMethod

    Please can you explain with a example code.. Thanks...
Page 1 of 3 123 LastLast

Similar Threads

  1. [CLOSED] [2.0] IDMode Static
    By Timothy in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 27, 2012, 8:58 AM
  2. [CLOSED] Calling Static DirectMethod defined in an UserControl
    By ISI in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 05, 2011, 9:16 AM
  3. Replies: 13
    Last Post: May 16, 2011, 1:26 PM
  4. [CLOSED] Difference between DirectMethod , DirectEvent, Static DirectMethod
    By syllabusarq in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 11:37 AM
  5. [CLOSED] DirectEvent or static DirectMethod?
    By macap in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 23, 2010, 12:31 PM

Posting Permissions