Results 1 to 6 of 6

Thread: Form submit & Asp.net Handler ASHX

  1. #1
    Sencha User
    Join Date
    Oct 2013
    Posts
    25
    Answers
    1

    Default Answered: Form submit & Asp.net Handler ASHX

    Hi,
    i am new to ExtJs.
    I try to post data to a ASP.NET Handler.
    I be able to to submit form data to the handler, i get the data and send the response, like i have seen in many examples.

    My issue is that when i submit data to the handler, even if i see in fiebug all correct, the json response and the 200 as status, the browser remains on the handler url and the form submit callback is never called.

    Can someone explain me in details how i can do the submit correctly ? Can someone have a working example ? I use Visual Studio 2010 and ASP.NET WebForms.

    Thank in advance,
    Giuseppe.

  2. Might be related to your form action:
    http://docs.sencha.com/extjs/4.2.1/#...StandardSubmit

    If not, please post your form so we can see what might be happening.

  3. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Might be related to your form action:
    http://docs.sencha.com/extjs/4.2.1/#...StandardSubmit

    If not, please post your form so we can see what might be happening.

  4. #3
    Sencha User
    Join Date
    Oct 2013
    Posts
    25
    Answers
    1

    Default This is my code

    Hi Gary, thank you for reply.

    the code for the form is:
    Code:
        <div id="divForm"></div>
        
    
        <script language="javascript" type="text/javascript">
    
            Ext.onReady(function () {
    
                var simple = new Ext.FormPanel({
                    labelWidth: 75,
                    scope: this,
                    frame: true,
                    standardSubmit: true,
                    title: 'Simple Form',
                    bodyStyle: 'padding:5px 5px 0',
                    width: 350,
                    defaults: { width: 230 },
                    defaultType: 'textfield',
    
                    items: [{
                        fieldLabel: 'First Name',
                        name: 'first',
                        allowBlank: false
                    }, {
                        fieldLabel: 'Last Name',
                        name: 'last'
                    }, {
                        fieldLabel: 'Company',
                        name: 'company'
                    }, {
                        fieldLabel: 'Email',
                        name: 'email',
                        vtype: 'email'
                    }, new Ext.form.TimeField({
                        fieldLabel: 'Time',
                        name: 'time',
                        minValue: '8:00am',
                        maxValue: '6:00pm'
                    })
            ],
                    buttons: [{
                        text: 'Save',
                        handler: function () {
                            simple.getForm().submit({
                                url: 'http://localhost:10861/Workers/Update2.ashx',
                                method: 'POST',
                                waitMsg: 'Invio Dati...',
                                success: function (form, action) {
                                    Ext.MessageBox.show({
                                        title: 'Success !',
                                        msg: 'Changes saved successfully<br />',
                                        icon: Ext.MessageBox.INFO
                                    })
                                },
                                failure: function (form, action) {
                                    Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response');
                                }
                            });
                        }
                    },
                    {
                        text: 'Cancel',
                        handler: function () {
                            simple.getForm().reset();
                        }
                    }]
                });
    
                simple.render('divForm');
            });
        </script>
    the code of the handler, is a simple version:

    Code:
        public class Update2 : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                ResponseBase rb = new ResponseBase(true, "OK Message !");
    
                context.Response.ContentType = "application/json";
                context.Response.Write(rb);
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    
        public class ResponseBase
        {
            public bool success = true;
            public string message = "ok";
    
            public ResponseBase()
            {
                this.success = true;
                this.message = "ok";
            }
    
            public ResponseBase(bool success, string message)
            {
                this.success = success;
                this.message = message;
            }
    
            public override string ToString()
            {
                return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter());
            }
        }
    As you can see, i simply response with the expected json answer {success: true}

    What happen is that the ExtJs callback is not called and i remain on the ashx handler page, that show me the json response.

    I can't understand where i am wrong. I follow many example on the .net, but i can't be able to work the form

    I hope you have the right answer. I am sure that i do some stupid error, but i am blocked on that

    Bye,
    Giuseppe.

  5. #4
    Sencha User
    Join Date
    Oct 2013
    Posts
    25
    Answers
    1

    Default

    UPDATE:
    I try to use not a asp.net webform, but a simple html page.
    The result is the same, the callback is not called.

    Giuseppe.

  6. #5
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,199
    Answers
    87

    Default

    I think Gary has point

    Code:
    standardSubmit: true,
    is causing this behaviour.

  7. #6
    Sencha User
    Join Date
    Oct 2013
    Posts
    25
    Answers
    1

    Default

    Hi tvanzoelen,
    you and Gary are rights.

    I try to delete that line, and BAM, the form works like a charm.

    Thank you very much.
    Giuseppe.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •