在下拉列表中添加列表项时无效的回发或回调参数

时间:2015-04-23 08:10:16

标签: javascript asp.net

我使用javascript在下拉列表中添加列表项,当我点击提交按钮时出现此错误

 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:DropDownList ID="dropdownlist" runat="server"></asp:DropDownList>

<script>
        var arr = "john,bob,david".split(',');
        for (var i = 0; i < arr.length; i++) {
            $('#dropdownlist').append('<option value="'+arr[i]+'">'+arr[i]+'</option>');
        }
</script>

我知道这个问题已被提出,但解决方案都没有对我有用。

1 个答案:

答案 0 :(得分:0)

我无法解决这个问题,但我找到了替代方法。

我没有使用asp下拉列表,而是使用html用于相同目的,并使用Request对象获取服务器端的值。