当我从客户端返回一个页面时,我得到以下错误。我有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

当前回答

以上这些方法对我都没用。经过更多的挖掘,我意识到我忽略了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标签。

其他回答

当我在ItemDataBound上添加id时,它没有给我错误,但它没有给我命令名。它返回命令名为空。然后我添加了命令名以及ItemDataBound。然后它解决了同样的问题。谢谢Nilesh,好建议。它起作用了:)

问题是ASP。NET不会知道这个额外的或已删除的列表项。 你有很多选择(如下所示):

禁用eventvalidation(这是个坏主意,因为你损失了一点安全性,而代价却很小)。 使用ASP。NET Ajax UpdatePanel。(如果你添加或删除列表框,将列表框放在更新面板中并触发更新。通过这种方式,viewstate和相关字段得到更新,eventvalidation将通过。) 忘记客户端,使用经典的回发并添加或删除listitems服务器端。

在本例中,将id添加到网格的RowDataBound中的按钮。它会解决你的问题。

The following example shows how to test the value of the IsPostBack property when the page is loaded in order to determine whether the page is being rendered for the first time or is responding to a postback. If the page is being rendered for the first time, the code calls the Page.Validate method. The page markup (not shown) contains RequiredFieldValidator controls that display asterisks if no entry is made for a required input field. Calling Page.Validate causes the asterisks to be displayed immediately when the page is rendered, instead of waiting until the user clicks the Submit button. After a postback, you do not have to call Page.Validate, because that method is called as part of the Page life cycle.

 private void Page_Load()
    {
        if (!IsPostBack)
        {      
        }
    }

我遇到了同样的问题,两个列表框和两个按钮。

列表框中的数据是从数据库中加载的,您可以通过单击按钮在框之间移动项目。

我收到了一个无效的回发。

结果是数据中有回车换行符,当显示在列表框中时无法看到。

在除ie10和ie11之外的所有浏览器中都运行良好。

拆下车架回换线,一切正常。