当我从客户端返回一个页面时,我得到以下错误。我有JavaScript代码,修改asp:ListBox在客户端。

我们如何解决这个问题?

错误详情如下:

Server Error in '/XXX' Application.

--------------------------------------------------------------------------------
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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: 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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: 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.]
   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +2132728
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +108
   System.Web.UI.WebControls.ListBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +274
   System.Web.UI.WebControls.ListBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +11
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +353
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1194

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

当前回答

检查绑定控件的数据。一些无效数据破坏了ValidateEvent。

其他回答

我实现了一个嵌套的网格视图,我也遇到了同样的问题。我使用了LinkButton而不是像这样的图像按钮:

在我有这样的专栏之前:

<asp:TemplateField ItemStyle-Width="9">
  <ItemTemplate>
 <asp:ImageButton ID="ImgBtn" ImageUrl="Include/images/gridplus.gif" CommandName="Expand"
                        runat="server" />
  </ItemTemplate>
</asp:TemplateField>

我像这样替换了。

<asp:TemplateField>
<ItemTemplate>
     <asp:LinkButton  CommandName="Expand" ID="lnkBtn"  runat="server" ><asp:Image  ID="Img"  runat="server" ImageUrl="~/Images/app/plus.gif" /></asp:LinkButton>
      </ItemTemplate>
</asp:TemplateField> 

我有同样的问题与Repeater,因为我有一个网页与一个网站的Repeater控件,已启用EnableEventValidation开关。这并不好。我得到无效的回发相关异常。

对我来说有用的是为Repeater设置EnableViewState="false"。它的优点是使用起来更简单,就像关闭网站或网页的事件验证一样简单,但是范围比关闭事件验证要小得多。

正如Nick B说的,这对我很有用在某些情况下你必须删除换行符。看一下代码:

错误的方法:

<asp:DropDownList ID="DropDownList1" runat="server">
    <asp:ListItem Selected="True">
            Item 1</asp:ListItem>
    <asp:ListItem>
            Item 2</asp:ListItem>
    <asp:ListItem>
            Item 3</asp:ListItem>
</asp:DropDownList>

-对道:

<asp:DropDownList ID="DropDownList1" runat="server">
    <asp:ListItem Selected="True">Item 1</asp:ListItem>
    <asp:ListItem>Item 2</asp:ListItem>
    <asp:ListItem>Item 3</asp:ListItem>
</asp:DropDownList>

我只在IE10+中遇到过

以上这些方法对我都没用。经过更多的挖掘,我意识到我忽略了2个表单应用在页面上,这是导致问题的原因。

<body>
<form id="form1" runat="server">
<div>
        <form action="#" method="post" class="form" role="form">
        <div>
        ...
        <asp:Button ID="submitButton" runat="server"
        </div>
</div>
</body>

注意,最近ASP。NET已经开始考虑iframes在一个表单标签中包含一个表单标签在iframe文档本身是一个嵌套框架。为了避免这个错误,我不得不将iframe移出form标签。

我通过没有将ListBox添加到父Page/Control控件集合来解决这个确切的错误。因为我真的不需要任何服务器端功能。我只是想用它来输出自定义服务器控件的HTML,这是我在OnRender事件处理程序中自己做的。我希望使用该控件可以使我不必编写自己的html响应。

这个解决方案可能不适合大多数人,但它使ASP。NET对控件执行ValidateEvent,因为控件在回发之间不会保留在内存中。

此外,我的错误是由选定的列表项是一个项目,不是在前回发的列表框。希望能帮到谁。