[CLOSED] DirectMethod's problem

  1. #1

    [CLOSED] DirectMethod's problem

    Hi,

    In the next sample:
    <%@ Page Language="C#"  %>
    <!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">
        <body>
        <ext:ResourceManager runat="server" />
        <script runat="server">
        [DirectMethod]
        public void SetTimeStamp()
        {
            this.Label1.Text = string.Concat("Server Time: ", DateTime.Now.ToLongTimeString());
        }
    </script>
    
    <ext:Button ID="Button5" runat="server" Text="Click Me" Icon="Lightning">
        <Listeners>
            <Click Handler="App.direct.SetTimeStamp();" />
        </Listeners>
    </ext:Button>
     <ext:Label ID="Label1" runat="server" Format="Server Time: {0}" Text='<%# DateTime.Now.ToLongTimeString() %>' AutoDataBind="true" />
     </body>
     </html>
    When click into button, not call to SetTimeStamp method and call to REST View Controller method.

    Any idea?

    Thanks,
    Last edited by Daniil; Jun 12, 2012 at 4:16 PM. Reason: [CLOSED]
  2. #2
    Hi,

    DirectMethods/DirectEvents with code behind server handlers should not be used in MVC.

    They should call controller actions.

    Example View
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    
    <%@ 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 runat="server">
        <title>Ext.Net.MVC v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:Label 
            ID="Label1" 
            runat="server" 
            Format="Server Time: {0}" 
            Text='<%# DateTime.Now.ToLongTimeString() %>' 
            AutoDataBind="true" />
    
        <ext:Button runat="server" Text="Update">
            <Listeners>
                <Click Handler="Ext.net.DirectMethod.request({
                                    url : '/Test/Update',
                                    params : {
                                        labelId : 'Label1'
                                    }
                                });" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Example Controller Action
    public ActionResult Update(string labelId)
    {
        AjaxResult r = new AjaxResult();
        Label label = X.GetCmp<Label>(labelId);
        label.Text = DateTime.Now.ToLongTimeString();
    
        return r;
    }

Similar Threads

  1. DirectMethod problem
    By abhijit in forum 1.x Help
    Replies: 4
    Last Post: Dec 23, 2011, 12:43 PM
  2. [CLOSED] DirectMethod with UserControl Problem
    By nhg_itd in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 21, 2011, 8:00 AM
  3. [CLOSED] DirectMethod.Request Problem
    By tansu in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Oct 28, 2010, 8:18 AM
  4. Replies: 2
    Last Post: Oct 08, 2010, 7:09 PM
  5. [CLOSED] [1.0]Problem with directMethod from custom Combobox
    By capecod in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 29, 2010, 12:52 PM

Posting Permissions