Success function in calling Direct Method..help!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Success function in calling Direct Method..help!

    Hi...

    i want use success function in after calling Direct Method. I have something like this:

    <ext:XScript runat="server" ID="scripts">
    <script type="text/javascript">

    function EmpClick() {
    var frm = Ext.getCmp("FormPanel1");
    if (frm.isValid()) {
    Ext.Net.DirectMethods.UpdateRecA(
    {
    success: function (result) {
    #{FormPanel1}.getForm().updateRecord(#{GridPanel1} .getSelectionModel().getSelected());
    },
    failure: function (errorMsg) {
    Ext.Msg.alert('Failure');
    }
    });
    }
    }

    </script>
    </ext:XScript>


    and the following Direct Methods :

    [DirectMethod]
    public void UpdateRecA()
    {
    string updateEmployee = "update [dbo].[tbl_Employee] set [FirstName]=' " + test + "' where employeeID = '5'";
    SQLHelper spConnectionObject = new SQLHelper();
    spConnectionObject.GetExecuteNonQueryByCommand(upd ateEmployee, CommandType.Text);

    }

    when i run this, I'm getting the error in browser: Ext.Net is undefined
    [Break On This Error] Ext.Net.DirectMethods.UpdateRecA ....

    And, when I remove success/failure function like this
    ....
    if (frm.isValid()) {
    Ext.Net.DirectMethods.UpdateRecA();
    }
    ....

    it works fine!
    As you see, my goal is when I update record in DB using direct method, then I want on success to update the record in grid using success: function (result) {
    #{FormPanel1}.getForm().updateRecord(#{GridPanel1} .getSelectionModel().getSelected());
    }


    Please, help!

    Thank you, ABob
    Last edited by Aleksa007; Mar 05, 2011 at 11:33 AM.
  2. #2
    Hi Aleksa... you need to sent a "response" from your code behind you have to code your function like this...

    [DirectMethod]
    public DirectResponse UpdateRecA()
    {
        DirectResponse response = new DirectResponse();
        try
        {
            string updateEmployee = "update [dbo].[tbl_Employee] set [FirstName]=' " + test + "' where employeeID = '5'";
            SQLHelper spConnectionObject = new SQLHelper();
            spConnectionObject.GetExecuteNonQueryByCommand(upd ateEmployee, CommandType.Text);
            response.Result = [What ever you want to returt to the success: function(result)] 
            response.Success = true;
        }
        catch (Exception ex)
        {
            response.Success = false;
            response.ErrorMessage = ex.Message;
        }
        return response;
    }
    Hope it Helps you...

    Greetings
  3. #3
    Hi,

    You don't need DirectResponse
    Please see the following sample
    https://examples1.ext.net/#/Events/D...ds/Exceptions/

Similar Threads

  1. Replies: 7
    Last Post: Oct 21, 2014, 6:22 AM
  2. Replies: 0
    Last Post: Mar 08, 2012, 9:45 AM
  3. Replies: 2
    Last Post: Oct 12, 2011, 7:49 AM
  4. Replies: 2
    Last Post: Apr 27, 2011, 2:58 PM
  5. Replies: 1
    Last Post: Mar 11, 2011, 2:54 PM

Posting Permissions