开发者

avoid viewstate when post using jquery

开发者 https://www.devze.com 2022-12-26 07:20 出处:网络
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...

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,
        contentT开发者_StackOverflow中文版ype: "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=test%40hotmail.com&username=&password=&retypePassword=&hiddenInputToUpdateATBuffer_CommonToolkitScripts=0


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!");
        }
    });
}
0

精彩评论

暂无评论...
验证码 换一张
取 消