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

当前回答

这个问题的一个简单解决方案是在页面加载时使用IsPostBack检查。这样问题就解决了。

其他回答

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

这个问题的一个简单解决方案是在页面加载时使用IsPostBack检查。这样问题就解决了。

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

Ie.

public class ListBoxNoEventValidation : ListBox 
{
}

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

如果您使用Ajax更新面板。添加<Triggers>标签,并在其中使用<asp:PostBackTrigger…/>触发按钮或控件导致回发

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

我希望我能给你投票,阿米尔(唉,我的代表太低了。)我只是有这个问题,改变这个工作就像一个冠军在我的网格视图。稍微提一下,我认为有效的代码是:ButtonType="Link"

我怀疑这是因为当你点击“编辑”时,你的编辑变成了“更新”和“取消”,然后在提交时又变成了“编辑”。这些变化的控件让。net很不舒服。