Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何更新其列表项由jQuery AJAX调用添加的ASP下拉列表:错误无效回发或回调_Javascript_C#_Jquery_Asp.net_Ajax - Fatal编程技术网

Javascript 如何更新其列表项由jQuery AJAX调用添加的ASP下拉列表:错误无效回发或回调

Javascript 如何更新其列表项由jQuery AJAX调用添加的ASP下拉列表:错误无效回发或回调,javascript,c#,jquery,asp.net,ajax,Javascript,C#,Jquery,Asp.net,Ajax,我有一个简单的问题,我把它复杂化了。我的web应用程序有一个ASP下拉列表,我希望从数据库中填充该下拉列表的值。因此,我使用jquery和Ajax执行并动态地将列表项添加到下拉列表中,我成功地做到了这一点。但是,只要我选择一个值并点击submit按钮,我就会得到 Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> i

我有一个简单的问题,我把它复杂化了。我的web应用程序有一个ASP下拉列表,我希望从数据库中填充该下拉列表的值。因此,我使用jquery和Ajax执行并动态地将列表项添加到下拉列表中,我成功地做到了这一点。但是,只要我选择一个值并点击submit按钮,我就会得到

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.
带有更新的ASP下拉列表面板如下所示

$.ajax({
    type: "POST",
    url: "salesQuote.aspx/getLabelAndValue",
    data: "{fieldName: \"tier\"}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
         console.log("karan");
         $.each(msg.d, function () {
               $("#tier").append($("<option></option>").val(this['Value']).html(this['Text']));
         });
    },
    error: function () {                   
           alert("Failed to load names");
    }
});
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
     <ContentTemplate>
           <asp:DropDownList  class="form-control" ID="tier" runat="server" AutoPostBack="true" OnSelectedIndexChanged="tierAccessChange" >
           </asp:DropDownList>
     </ContentTemplate>
     <triggers>
         <asp:asyncpostbacktrigger controlid="tier" eventname="SelectedIndexChanged" />
     </triggers>
</asp:UpdatePanel>

我不知道下一步该做什么,也不知道我所做的是对的。点击下拉控件中的提交按钮后,请告诉我如何获得所选值的正确方向

编辑1:我尝试在web配置中添加。我消除了错误,但在提交后无法在控件中获取所选值

<system.web>
   <pages enableEventValidation="false"/>
</system.web>

网络表单倾向于让你按照他们的方式做事。您可以尝试将新值发布到服务器,然后将该选项添加到服务器代码中的下拉列表中,而不是将该选项添加到客户端的控件中。(即使从客户端添加,您也可能希望在收到新值后在服务器端添加它。否则,它不会作为列表中的一项保留。它将消失。)

另外,您如何读取下拉列表的值?ASP.NET可能无法将其识别为服务器控件中的选项,但在提交表单时仍会将其发布。您可以直接从
Request.Form[“YourDropDownClientId”]中读取它。

<system.web>
   <pages enableEventValidation="false"/>
</system.web>