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

当前回答

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

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

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

其他回答

我用的是数据列表,我的按钮也出现了同样的错误。我只是使用IsPostBack检查和填充我的控件,问题就解决了!太棒了! !

对我有用的是将以下代码从page_load移动到page_prerender:

lstMain.DataBind();
Image img = (Image)lstMain.Items[0].FindControl("imgMain");

// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
    cs.RegisterStartupScript(cstype, csname1, "<script language=javascript> p=\"" + img.ClientID + "\"</script>");
}

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

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

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

这就是我得到它的原因:

我有一个ASP:ListBox。最初它是隐藏的。在客户端,我将通过AJAX填充它的选项。用户选择了一个选项。然后,当单击Submit按钮时,服务器会对ListBox感到奇怪,因为它不记得它有任何选项。

因此,我所做的是确保在将表单提交回服务器之前清除所有列表选项。这样服务器就不会抱怨,因为列表到客户端时是空的,返回时也是空的。

排序! !