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

当前回答

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)
        {      
        }
    }

其他回答

如果你把UseSubmitBehavior="True"改成UseSubmitBehavior="False",你的问题就解决了

<asp:Button ID="BtnDis" runat="server" CommandName="BtnDis" CommandArgument='<%#Eval("Id")%>' Text="Discription" CausesValidation="True" UseSubmitBehavior="False" />

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

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

(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/

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

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