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

当前回答

如果您正在使用gridview,而不是在pageload inside !ispostback中绑定gridview,那么当您单击gridview中的编辑和删除行时,将出现此错误。

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        bindGridview();
        }

其他回答

Ajax UpdatePanel可以做到这一点,我认为这是最简单的方法,忽略Ajax回发开销。

我用过DataGrid。其中一列是“选择”按钮。当我点击任何一行的“选择”按钮时,我收到了这个错误消息:

无效的回发或回调参数。事件验证使用配置或 <%@ Page EnableEventValidation="true" %>出于安全考虑,此特性验证回发或回发的参数 回调事件源自最初呈现它们的服务器控件。如果数据是有效的和预期的,则使用 ClientScriptManager。RegisterForEventValidation方法,以便注册回发或回调数据进行验证。

我改了几个密码,最后成功了。我的体验路线:

1)我把页面属性改为EnableEventValidation="false"。但这并没有起作用。(这不仅危险 出于安全原因,我的事件处理程序没有被调用:void Grid_SelectedIndexChanged(对象发送者,EventArgs e)

2)实现ClientScript。渲染方法中的RegisterForEventValidation。但这并没有起作用。

protected override void Render(HtmlTextWriter writer)
{
    foreach (DataGridItem item in this.Grid.Items)
    {
        Page.ClientScript.RegisterForEventValidation(item.UniqueID);
        foreach (TableCell cell in (item as TableRow).Cells)
        {
            Page.ClientScript.RegisterForEventValidation(cell.UniqueID);
            foreach (System.Web.UI.Control control in cell.Controls)
            {
                if (control is Button)
                    Page.ClientScript.RegisterForEventValidation(control.UniqueID);
            }
        }
    }
}

3)我改变了我的按钮类型在网格列从PushButton到LinkButton。它工作!(" ButtonType = " LinkButton”)。我认为如果你可以改变你的按钮到其他控件,如“LinkButton”在其他情况下,它会正常工作。

我也遇到过同样的问题

刚刚添加了一个条件if(!IsPostBack),它工作得很好:)

供参考,我有同样的错误消息的问题,这是我在同一页上有2个表单标签。一个在母版页,一个在页面本身。一旦我删除了第二个形式标签对,问题就消失了。

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

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

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

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

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

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