我有一个ASP.Net托管网站,它显示结果列表作为DataGrid或ASP.Net Repeater与结果分页.
如果通过按下上一个/下一个选项卡快速滚动页面,有时会抛出HttpUnhandledException并呈现调试页面而不是下一个结果列表.
调试屏幕如下:
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentException: Invalid postback or callback argument. Event validation is enabled usingin 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. at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) at System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace --- at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.contacts_default_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我在http://blogs.msdn.com/amitsh/archive/2007/07/31/why-i-get-invalid-postback-or-callback-argument-errors.aspx找到了这样的错误.
但建议的解决方案是设置为false,但这似乎创建了一个安全漏洞.这些评论推荐了几种替代方案,但由于它们需要在我的网站中使用的每个DataGrid或Repeater控件中添加代码,因此它们看起来相当复杂.
有没有更普遍的解决方案可以在不牺牲安全性的情况下完成?
回发时未提供页面上的隐藏字段.这些领域有几个,它们通常是ASP.Net提供的"魔术"所必需的.
在您的页面指令中,您可以在页面指令中放置enableEventValidation = false以将其关闭,但这可能是不可取的.
您可以移动编写代码以将元素移动到页面顶部
最后,我相当确定最近在Service Pack或3.5中修复了这个问题.
- 编辑 -
我刚刚找到了设置:RenderAllHiddenFieldsAtTopOfForm
根据MSDN支持以下版本:3.5 SP1,3.0 SP2,2.0 SP2