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

当前回答

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

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

其他回答

这里没有提到的另一种方法是子类化ListBox

Ie.

public class ListBoxNoEventValidation : ListBox 
{
}

如果你子类化了system . web . ui . supportsevenvalidation属性,除非你显式地把它添加回来,否则它永远不会调用验证例程。这对任何控件都有效,而且是我发现的在一个控件的基础上“禁用”它的唯一方法(即,不是页面级别)。

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

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

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

(1) EnableEventValidation = " false "...................这对我没用。

(2) ClientScript.RegisterForEventValidation……这对我没用。

解决方案1:

在GridView中将Button/ImageButton更改为LinkButton。它的工作原理。(但我喜欢ImageButton)

研究:Button/ImageButton和LinkButton使用不同的回发方法

原文:

http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx

解决方案2:

在OnInit()中,输入如下代码来设置Button/ImageButton的唯一ID:

protected override void OnInit(EventArgs e) {
  foreach (GridViewRow grdRw in gvEvent.Rows) {

  Button deleteButton = (Button)grdRw.Cells[2].Controls[1];

  deleteButton.ID = "btnDelete_" + grdRw.RowIndex.ToString();           
  }
}

原文:

http://www.c-sharpcorner.com/Forums/Thread/35301/

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

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

最好的选择是使用隐藏字段,不禁用事件验证,也改变每个列表框,下拉列表选择与runat服务器属性