使用jquery发布时避免使用viewstate

时间:2010-04-12 17:19:36

标签: asp.net jquery json viewstate

当我从jquery发帖时,我怎么能避免或者不发送viewstate?

我尝试使用.aspx EnableViewState =“false”,但没有效果......

这是iam如何发布我的页面:

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); 
        }
    };

任何帮助?

发送到服务器的数据:

  

__ 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 =测试%40hotmail.com&安培;用户名=安培;密码=安培; retypePassword =安培; hiddenInputToUpdateATBuffer_CommonToolkitScripts = 0

1 个答案:

答案 0 :(得分:1)

您是否考虑过使用Page Method?

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

它的行为与Web服务非常相似,只会发送调用方法所需的少量JSON。

您也可以执行此操作using JQuery.

编辑:

从客户端进行此调用可以这么简单:

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