View Full Version : Best way to submit a form using WebMethod?

12 Nov 2009, 3:59 PM
I want to use a (.NET) WebMethod in the codebehind class to process my form.

Question (1) - what is the best way to pass form data into the method?

Let's say that method finds that 3 fields are bad.

Question (2) - what is the best way for that method to return "fail" and apply the "invalid" markings to those fields?

I have a feeling that this is the part where I'll have to learn how to encode/decode JSON? :)

13 Nov 2009, 9:42 AM
From everything I'm reading it seems form submits are always focused on submitting to a specific URL.

Is there an easy way to plug a webmethod into the same functionality?

13 Nov 2009, 12:22 PM
So I figured out a way to do this using Ext.Ajax.request.

First, the codebehind method:

public static string SubmitForm(string password)
return "WEEEE" + password;
// return {"d":"WEEEEblah"}

The button handler:

url: "GraduateStudents.aspx/SubmitForm",
method: "post",
jsonData: {password: "blah"},
headers: { 'Content-Type': 'application/json;charset=utf-8' },
success: function(response,options)
alert("Success: " + response.responseText);
failure: function(response,options)
alert("Fail: " + response.responseText);

This returns {"d":"WEEEEblah"}

... now, I still need to figure out how to take a response and apply it to form validation. Any takers?