2014-03-26 64 views
0
<script type="text/javascript"> 
    var s = false; 
    $(document).ready(function() { 
     $("#btnSaveEducation").click(function() { 
      s = true; 
     }); 

     window.onload = function() { 

      if (s == false) { 
       var select = document.getElementById("year"); 
       for (var i = 2011; i >= 1900; --i) { 
        var option = document.createElement('option'); 
        option.text = option.value = i; 
        select.add(option, 0); 
       } 
      } 
     }; 
    }); 
</script> 

.... 
... 
<body> 
<asp:DropDownList ID="year" runat="server" name="year"> 
         </asp:DropDownList> 
</body> 
.... 
.. 

你好。 在Asp.Net卷筒纸, 我得到这个error当我click btnSaveEducationAsp.net Web窗体错误:回发或回调参数无效

[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.] 

为什么? 谢谢。

回答

2

Dy默认你不能在jquery或java-script的下拉列表中添加选项。

因为Asp.net在回发后检查每个控件。

您可以更改页面指令如下

<%@ Page ... EnableEventValidation="false" %> 

,这将导致在服务器端这是不好的事情没有验证。

如果你想实现上述,你可以使用html drop下来,并使用hidden field并从hidden field获得选定的值,而不是下拉它将工作。在SO

  1. asp.net: Invalid postback or callback argument
+0

当我点击F5在Visual Studio中,一切都很好。在下拉列表中有几年。当我刷新页面时,一切都很好。 但是,当我点击按钮,我得到这个错误。 – Jeyhun

+0

我已经完成了。已经没有错误。但是你怎么看?是否可以引起其他proplem为其他元素添加“EnableEventValidation =”false“属性? – Jeyhun

+0

@Shekhar Asp.net检查每个控件后回发....它是什么意思..? –

0

类似的问题,只是把这个代码在你的aspx文件:

如果你已经有类似<%@页... EnableEventValidation =“false”%>

相关问题