[CLOSED] Direct Method Not firing.

  1. #1

    [CLOSED] Direct Method Not firing.

    Hello again,
    I have a commandColumn that generates message box with yes/no confirmation then fires directmethod in code behind if yes.
    Code below was working in 1.7, now in v4 seems to have broken.
    Given this a good couple of hours with no luck, the most I can get is the message box to fire but nothing on the yes button click.
    Getting this error in the browser console if it helps. "Uncaught TypeError: Ext.Msg.Alert is not a function"

    <script type="text/javascript">
            var deleteOrder = function (grid, command, record, row) {
    
    
                Ext.Msg.show({
                    title: 'Delete Order? This cannot be undone!',
                    msg: 'Deleting an order will delete all associated tickets, are you sure?',
                    buttons: Ext.Msg.YESNO,
                    icon: Ext.Msg.QUESTION,
                    fn: function (btn) {
    
                        
                        if (btn == 'yes') {
                           
                            Ext.net.DirectMethods.DeleteOrder(id);
                            
                            
                        }
    
                    }
                });
    
    
    
            }
    </script>
     <ext:GridPanel ID="GridPanelOrderTickets" runat="server" StripeRows="true" Title="Orders"
                TrackMouseOver="true" Height="320" StoreID="SearchOrderStore" AutoScroll="true" Frame="true" Width="1400">
                <ColumnModel ID="ColumnModel2" runat="server">
                    <Columns>
     <ext:CommandColumn runat="server" Width="80" Header="Delete">
                            <Commands>
                                <ext:GridCommand Icon="Delete">
                                    <ToolTip Text="Delete Order" />
                                </ext:GridCommand>
                            </Commands>
                            <Listeners>
                                <Command Fn="deleteOrder" />
                            </Listeners>
                         
                        </ext:CommandColumn>
     </Columns>
                </ColumnModel>
    
     <DirectMethod()>
        Public Sub DeleteOrder(ByVal OrderID As Integer)
            Try
                'Do stuff in here with OrderID
    
            Catch ex As Exception
                ShowInfoBox("Error", ex.Message, MessageBox.Icon.ERROR, False, "")
            End Try
        End Sub
    Last edited by fabricio.murta; Mar 15, 2019 at 7:12 PM. Reason: no feedback from the user in 7+ days
  2. #2
    Hello Guy!

    Sorry for the delay to reply for this inquiry, mistaken this by the other active thread we have.

    The response you're getting suggests you're getting an exception in your code behind call, and ShowInfoBox() method is making a response calling Ext.Msg.Alert(), which does not exist in fact, missed by just a case. While C# server-side code is UpperCamelCased, JavaScript client-side code is lowerCamelCased in class members (functions/methods, properties/config_options).

    You want either to call the correct client-side method, Ext.Msg.alert(), or use server-side code to build up the message box response, which is highlighted in in this example: MessageBox > Basic > Overview

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi fabricio.murta,

    sorry I should have been more clear, the alert 'Ext.Msg.Alert is not a function" was not the issue at hand but a error in my testing before I posted in the forum.
    So the below java script is being hit from clicking the delete command column in my grid panel fine, and from my browser debug I can see the correct ID value is being passed from

     <Listeners>
                                <Command Handler="deleteOrder(record.data.OrderID);" />
                            </Listeners>
    to this:

     <script type="text/javascript">
            var deleteOrder = function (id) {
                
    
                Ext.Msg.show({
                    title: 'Delete Order? This cannot be undone!',
                    msg: 'Deleting an order will delete all associated tickets, are you sure?',
                    buttons: Ext.Msg.YESNO,
                    icon: Ext.Msg.QUESTION,
                    fn: function (btn) {
    
                        if (btn == 'yes') {
                            
                            Ext.net.DirectMethods.DeleteOrder(id);
                            
                        }
    
                    }
                });
    
            }
    </script>
    However it is the Ext.net.DirectMethods.DeleteOrder(id); which seems to throw the error as "DirectMethods" is showing as undefined in the debug.

    If run through a debug on my current live version of EXT 1.7, the DirectMethods show all available c# code behind methods available.




    The code behind.
     <DirectMethod()>
        Public Sub DeleteTicket(ByVal TicketID As Integer)
            Try
    
                Dim DA = New DataAccess
    
                
    
                DA = Nothing
    
            Catch ex As Exception
                ShowInfoBox("Error", ex.Message, MessageBox.Icon.ERROR, False, "")
            End Try
        End Sub
  4. #4
    Hello Guy!

    Sorry the last response was not really helpful. Please refrain from posting isolate code snippets, as they are just making it more confuse to understand what your issue is. Simplifying the issue down to runnable test case would greatly help us understand your issue and effectively help you.

    If I understand well, your test case could be reduced to just this (runnable by just copy-pasting into a new file in a VB.NET project):

    <%@ Page Language="vb" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
        <DirectMethod()>
        Public Sub DeleteTicket(byVal TicketID As Integer)
            Ext.Net.X.Toast("Deleted order ID #" & TicketID)
        End Sub
    </script>
    
    <html>
    <head runat="server">
        <title>Ext.NET Example</title>
    
        <script type="text/javascript">
            function deleteTicket(num) {
                Ext.net.DirectMethods.DeleteTicket(num);
            }
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Button runat="server" ID="btn1" Text="Delete ticket">
                <Listeners>
                    <Click Handler="deleteTicket(1)" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    That would trigger the exception you pointed, for null reference when trying to call the DeleteTicket() Direct Method (notice I also took the liberty of renaming all DeleteOrder() into DeleteTicket() to make sense of the code).

    If that's the case, then you just need to change line 18 in the code above to this:

    App.direct.DeleteTicket(num);
    And you'll get the direct method working.

    We kindly ask you to take some time to review our forum guidelines, especially the part about building simplified test cases, as it will greatly help us improve the responses you receive in the forums:
    - Tips for creating simplified code samples
    - More Information Required
    - Forum Guidelines

    Posting the isolated code snippets not only diverges the focus from the actual issue, but could also expose your proprietary code, which is not something we don't want at all. Simplifying the code sometimes helps you find the issue by yourself, strip unrelated code that could include proprietary/copyrighted material, help focus on the actual issue, and get great responses! :)

    Hope you understand, and that now I found the reason of your failing code. The following thread has a little more about the change in namespace (which took place between Ext.NET 1.x to 2.x version change):
    - Ext.net.DirectMethods.XXXX
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello again, Guy!

    It's been some days since we last replied here, and still no feedback from you. Did the answer above help at all? Do you still need help with this issue? We're looking forward to your follow-up!

    We may mark this thread as closed if you don't post here in 7+ days from now. As we don't lock up the thread, you're always welcome to continue with the inquiry even if we marked it as 'closed'.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 2
    Last Post: May 13, 2014, 8:52 AM
  2. [CLOSED] Delay firing of Direct Method ...
    By rthiney in forum 2.x Premium Help
    Replies: 1
    Last Post: Apr 10, 2014, 4:28 PM
  3. Direct Method is not firing
    By amida in forum 2.x Help
    Replies: 1
    Last Post: Mar 25, 2013, 7:24 AM
  4. [CLOSED] Output Cache issue with Direct Method / Direct Event
    By amitpareek in forum 1.x Premium Help
    Replies: 18
    Last Post: Mar 01, 2013, 5:03 AM
  5. UserControl Direct Method is not Firing...
    By nagesh in forum 2.x Help
    Replies: 3
    Last Post: Nov 29, 2012, 1:06 PM

Posting Permissions