当我从客户端返回一个页面时,我得到以下错误。我有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检查。这样问题就解决了。

其他回答

四分钟前我收到了同样的错误。然后我像你一样研究了半个小时。在所有论坛中,他们通常会说“添加页面enableEvent..”=假或真”。任何提出的解决方案都不能解决我的问题,直到我找到它。不幸的是,问题出在ASP。净按钮。我两秒钟前把它取下来了。我尝试用“imagebutton”替换,但这也是不可接受的(因为它给出了相同的错误)。

最后我已经替换为LinkButton。它似乎起作用了!

我有一个类似的问题,但我没有使用ASP。Net 1.1也没有通过javascript更新控件。 我的问题只发生在Firefox而不是IE(!)。

我在PreRender事件的下拉列表中添加了如下选项:

DropDownList DD = (DropDownList)F.FindControl("DDlista");
HiddenField HF = (HiddenField)F.FindControl("HFlista");
string[] opcoes = HF.value.Split('\n');
foreach (string opcao in opcoes) DD.Items.Add(opcao);

我的“HF”(隐藏字段)有换行符分隔的选项,如下所示:

HF.value = "option 1\n\roption 2\n\roption 3";

问题是HTML页面在代表下拉菜单的“选择”选项上出现了问题(我的意思是有换行符)。

所以我解决了我的问题加了一行

DropDownList DD = (DropDownList)F.FindControl("DDlista");
HiddenField HF = (HiddenField)F.FindControl("HFlista");
string dados = HF.Value.Replace("\r", "");
string[] opcoes = dados.Split('\n');
foreach (string opcao in opcoes) DD.Items.Add(opcao);

希望这能帮助到一些人。

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

Ie.

public class ListBoxNoEventValidation : ListBox 
{
}

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

在本例中,将id添加到网格的RowDataBound中的按钮。它会解决你的问题。

在将常规ASPX页面转换为Content页面时,我们也遇到了同样的问题。

有此问题的页面在其中一个Content部分内有一个</form>标记,因此在运行时呈现了两个表单结束标记,从而导致了此问题。从页面中删除额外的表单结束标记解决了此问题。