无效的回发或回调参数。当下拉列表填充jquery并且有回发时

时间:2012-09-19 07:28:00

标签: asp.net jquery

我先换了两个下拉列表框我要填写第二个。 我已经为此编写了一个jquery,如下所示

function BindModel() {
var makeCode = $('#ddMake').val();
var ddModel = $("#ddModel");
if (makeCode == "0") {
    return false;
}
else {
    $("#loading").show();
    $.ajax({
        type: "POST",
        url: "Services/GetModels.ashx",
        data: { 'makeCode': makeCode },
        success: function (data) {
            $("#loading").hide();
            $.each(data, function () {
                ddModel.append($("<option />").val(this.ModelCode).text(this.ModelName));
            });
        },
        error: function () {
            $("#loading").hide();
        }
    });
}

}

我有一个通用的http处理程序如下

context.Response.ContentType = "application/json";
        context.Response.ContentEncoding = Encoding.UTF8;
        if( context.Request["makeCode"]!=null)
        {
            var makeCode = context.Request["makeCode"].Trim();
            var lobjSearchProps = new CSearchAllProps
            {
                SearchValue = "%",
                MakeCode = makeCode
            };
            var allModelProps = new CModelRestrictionLogic().GetModels(lobjSearchProps).ToList();
            context.Response.Write(JSONHelper.GetJSON(allModelProps));    
        }

其中CModelRestrictionLogic()。GetModels(lobjSearchProps)是我的函数,它从数据库中获取数据。
和CModelRestrictionLogic()。GetModels(lobjSearchProps)将列表转换为jason。

一切都很好。但是,当我回复时,它会发出错误

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. 

我知道原因,因为我已经从jquery填充了下拉列表,因此收到错误 我还在init上编写了函数来填充已发布的值的数据,如下所示

 protected override void OnInit(EventArgs e)
    {
        var postedOptionValue = Request.Form[ddModel.UniqueID];
        ddModel.Items.Add(new ListItem(postedOptionValue));
        base.OnInit(e);
    }

我怎样才能摆脱这个价值。我不想使用enableEventValidation =“false”,因为它是一个安全问题。

请帮助。

0 个答案:

没有答案