gpt4 book ai didi

asp.net - 在使用 ASP.NET 事件验证时,如何防止半加载页面的表单提交出现异常?

转载 作者:行者123 更新时间:2023-12-02 18:42:57 26 4
gpt4 key购买 nike

我有一个页面,其中包含一些动态添加的按钮。如果在页面完全加载之前单击按钮,则会抛出经典异常:

Invalid postback or callback argument. 
Event validation is enabled using in configuration or 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.

我猜测 Viewstate 字段尚未加载到表单上,其他位正在提交。在保持事件验证的同时防止此错误的最佳方法是什么?

最佳答案

我回答过类似的问题here 。引用:

本质上,您需要在页面顶部加载 ViewState。在 .NET 3.5 SP1 中,RenderAllHiddenFieldsAtTopOfForm 属性已添加到 PagesSection 配置中。

Web.config

<configuration>

<system.web>

<pages renderAllHiddenFieldsAtTopOfForm="true"></pages>

</system.web>

</configuration>

有趣的是,它的默认值为 true。因此,本质上,如果您使用 .NET 3.5 SP1,则 ViewState 会自动呈现在表单顶部(在加载页面的其余部分之前),从而消除您遇到的 ViewState 错误。

关于asp.net - 在使用 ASP.NET 事件验证时,如何防止半加载页面的表单提交出现异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/254349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com