views:

148

answers:

1

how can i avoid or rather not send viewstate when i post from jquery?

i try to put on the .aspx EnableViewState="false" but has no effect...

here is how iam posting my page:

var json = "{'firstname':'" + escape(firstname.val()) + "','surname':'" + surname.val() + "','day_fi':'" + day_fi.val() + "'}";
var ajaxPage = "wizard_data_process.aspx?returnId=0"; 
var options =
    {
        type: "POST",
        url: ajaxPage,
        data: json,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,
        success: function(response) {
            //alert("success: " + response);
        },
        error: function(msg) {
            //alert("failed: " + msg); 
        }
    };

any help?

Data sent to the server :

_EVENTTARGET=&_EVENTARGUMENT=&_VIEWSTATE=%2FwEPDwUKMTMyNDEzMjAzM2QYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFDGNieE5vTWlkTmFtZXiY9c%2FusiuXmmWoJcK9o1udk5EX&_EVENTVALIDATION=%2FwEWKAL9rv3PAgK5h62pDwKnq8goAo%2BUwaAKAp2VxakCAtyNr8EIAr%2Fiza4EAtKQxe0HAtKQ4e0HAoDiza4EAoTfzqgFAumw5MYJAt%2Bw5MYJAofGq70JArr1ub4HAuKw5MYJAqfRtpcOArS3qtYNAtfYgLgBAu7YgLgBAu%2Bnq4AOAr2l1I8JAoz6iM8PAv2zgs4HAuXbmvMCAum1prUBApuktpcOApXyjvkGAuWixvECApSOke8IAt%2F1gtUKAsK1%2BeEBArKpwL0FAvfnuc0BAtb3964NAq%2Bm6rYIAvK94JEPAqCg9ZcMApmw76wEAsSXxu0O%2B%2F2DDTg9otIrNrwvY0ugwxYyULA%3D&txtFirstName=asdf&txtMiddleName=&txtLastName=&ddlSalutation=&ddlSuffix=&txtEmailAddress=&ddlGender=&txtDateOfBirth=&MaskedEditExtender1_ClientState=&ddlCountryOfBirth=&CascadingDropDown1_ClientState=%3A%3A%3A&ddlStateOfBirth=&CascadingDropDown2_ClientState=%3A%3A%3A&txtCityofBirth=&day_fi=DD&month_fi=MM&year_fi=YYYY&lastFour_fi=XXXX&countryPrefix_fi=%2B358&areaCode_fi=&phoneNumber_fi=&email_fi=nisarkhan%40hotmail.com&username=&password=&retypePassword=&hiddenInputToUpdateATBuffer_CommonToolkitScripts=0

+1  A: 

Have you considered using Page Method's instead?

[WebMethod]
public static void AddPerson(String name, Int32 age)
{  
    //implementation here  
}  

It acts much like a web service, and will only send the tiny amount of JSON required to make the method call.

You can also do this using JQuery.

EDIT:

Making this call from the client can be as simple as this:

function getPersonJson() {
    var name = $("#<%= Name.ClientID %>");
    var age = $("#<%= Age.ClientID %>");
    return json = "{name:'" + name.val() + "',age:'" + age.val() + "'}";
}

function callAddPerson() {
    var json = getPersonJson();

    $.ajax({
        type: "POST",
        url: "AddPersonPageMethod.aspx/AddPerson",
        data: json,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            alert("Success!");
        }
    });
}
Josh
Josh:i thought about it and in fact i attempt to do but i got stuck, like how would i be passing the data (in this case whatever the user entered in controls) to web method.do you have sample where i can see?thanks.
Abu Hamzah