PDA

View Full Version : Form submit & Asp.net Handler ASHX



melnac
15 Oct 2013, 12:01 PM
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.

Gary Schlosberg
17 Oct 2013, 10:36 AM
Might be related to your form action:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.action.StandardSubmit

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

melnac
18 Oct 2013, 11:39 AM
Hi Gary, thank you for reply.

the code for the form is:


<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:



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 :s

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

Bye,
Giuseppe.

melnac
21 Oct 2013, 11:25 AM
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.

tvanzoelen
21 Oct 2013, 11:59 AM
I think Gary has point


standardSubmit: true,

is causing this behaviour.

melnac
21 Oct 2013, 11:27 PM
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.