回发或回调参数无效。单击按钮时

发布于 2024-09-12 23:13:18 字数 1523 浏览 1 评论 0原文

我有一个带有各种控件的网页。其中两个是下拉列表。第一个下拉列表由 page_load 事件中的 xml 文件填充。这很好用。第一个下拉列表附加了一个级联下拉列表扩展器,每次第一个下拉列表中的选择发生更改时,该扩展器都会调用 Web 服务。这也很好用。在我的两个下拉列表下面有一个按钮可以将页面发回。但是,当我在第二个下拉列表中进行选择并单击按钮时,出现以下错误:

“/”应用程序中的服务器错误。 回发或回调参数无效。使用配置或 <%@ Page EnableEventValidation="true" %> 启用事件验证在一个页面中。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.ArgumentException:无效的回发或回调参数。使用配置或 <%@ Page EnableEventValidation="true" %> 启用事件验证在一个页面中。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用 ClientScriptManager.RegisterForEventValidation 方法注册回发或回调数据以进行验证。

来源错误:

执行当前 Web 请求期间生成未处理的异常。有关异常来源和位置的信息可以使用下面的异常堆栈跟踪来识别。

堆栈跟踪:

[ArgumentException:无效的回发或回调参数。使用配置或 <%@ Page EnableEventValidation="true" %> 启用事件验证在一个页面中。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。] System.Web.UI.ClientScriptManager.ValidateEvent(字符串uniqueId,字符串参数)+10945696 System.Web.UI.WebControls.DropDownList.LoadPostData(字符串postDataKey,NameValueCollection postCollection)+72 System.Web.UI.Page.ProcessPostData(NameValueCollection postData,布尔值fBeforeLoad)+507 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)+2071

抱歉,格式很糟糕。关于为什么抛出此错误以及如何防止它有什么建议吗?

谢谢,

I have a web page with various controls. Two of them are dropdownlists. The first dropdownlist gets populated from an xml file on the page_load event. This works fine. To the first dropdownlist a cascadingdropdownlist extender is attached which calls a webservice each time the selection in the first dropdownlist is changed. This works fine too. Underneath my two dropdownlists I have a button which posts the page back. However, when I have made a selection in the second dropdownlist and click the button I get the following error:

Server Error in '/' Application.
Invalid postback or callback argument. Event validation is enabled using 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 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 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) +10945696
System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) +72
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +507
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2071

Sorry for the terrible formatting. Any suggestions on why this error is thrown and how to prevent it?

Thanks,
Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

节枝 2024-09-19 23:13:18

这是 AJAX CascadingDropDown 扩展器的一个已知问题。

为了使其正常工作,您需要禁用事件验证。

这是讨论这个问题的一个线程:
http://forums.asp.net/t/1032053.aspx

我有同样的问题,这就是为什么我放弃使用 CascadingDropDown 扩展器而只使用常规的客户端下拉列表和一些 jQuery。

您有两个选择:

  1. 放弃 AJAX CascadingDropDown,用常规下拉菜单替换,使用 jQuery/javascript 在客户端点击时调用 Web 服务。
  2. 禁用页面上的事件验证。 (不推荐)。

事件验证可防止页面状态在请求之间被篡改。不幸的是,无论出于什么原因,AJAX CDDL 正是这样做的。

您不应该仅仅为了让 CDDL 工作而禁用它,因为它会影响整个页面并可能导致安全问题。

我的建议是,咬紧牙关——放弃 CDDL 并用 jQuery 代替。

It's a known problem with the AJAX CascadingDropDown extender.

In order for it to work properly, you need to disable event validation.

Here's a thread discussing the issue:
http://forums.asp.net/t/1032053.aspx

I had the same issue, that's why i ditched using the CascadingDropDown extender and just used regular client-side dropdownlist's and some jQuery.

You've got two options:

  1. Ditch the AJAX CascadingDropDown, replace with regular dropdowns, calling web service on client click with jQuery/javascript.
  2. Disable event validation on the page. (not recommended).

Event validation prevents the state of the page being tampered with between requests. Unfortunately, the AJAX CDDL does exactly this, for whatever reason.

It's not something you should disable just to get the CDDL working, as it will affect the entire page and can cause security issues.

My advice, bite the bullet - ditch the CDDL and replace with jQuery.

三月梨花 2024-09-19 23:13:18

我刚刚找到了我自己问题的答案。

问题是 AJAX 将新值添加到下拉列表中,但由于它们不在视图状态中,ASP.NET 会停止并出现错误。这里有一篇很棒的博客文章解释了如何解决这个问题,它对我很有用。

基本上,您只需对 dropdownlist 类进行子类化,即可摆脱 SupportsEventValidation 属性 -> ASP.NET 不再验证值,一切运行正常!

在这里阅读整篇文章:
对要删除的 DropDownList 进行子类化SupportsEventValidation 属性

I just found the answer to my own questions.

The problem is that AJAX adds the new values to the dropdownlist but as they're not in the viewstate ASP.NET stops with an error. There is a great blog post here which explains how to solve this problem, it worked great for me.

Basically you just subclass the dropdownlist class which get's rid of the SupportsEventValidation attribute -> ASP.NET does not validate the values anymore and everything runs fine!

Read the whole post here:
Subclassing the DropDownList to remove the SupportsEventValidation attribute

初与友歌 2024-09-19 23:13:18

我进行了很多搜索并最终得到了这个解决方法:
http:// avinashsing.sunkur.com/2011/03/24/dropdownlist-in-asp-net-does-not-retain-control-state/

对于通用用户,在您的父页面中:

受保护的子 cbGenericDropDownList_DataBound(发送者作为对象,e 作为 System.EventArgs)
如果不是 IsNothing(HttpContext.Current.Request(DirectCast(sender, DropDownList).UniqueID)) 那么
DirectCast(发送者, DropDownList).SelectedValue = _
HttpContext.Current.Request(DirectCast(发件人,DropDownList).UniqueID)
结束如果
结束子

,然后为页面中的每个 DropDownList 控件添加:
OnDataBound="cbGenericDropDownList_DataBound"

I've searched a lot and ended up with this workaround:
http://avinashsing.sunkur.com/2011/03/24/dropdownlist-in-asp-net-does-not-retain-control-state/

for Generic User, in your Parent Page:

Protected Sub cbGenericDropDownList_DataBound(sender As Object, e As System.EventArgs)
If Not IsNothing(HttpContext.Current.Request(DirectCast(sender, DropDownList).UniqueID)) Then
DirectCast(sender, DropDownList).SelectedValue = _
HttpContext.Current.Request(DirectCast(sender, DropDownList).UniqueID)
End If
End Sub

and then for each DropDownList Control in your page add:
OnDataBound="cbGenericDropDownList_DataBound"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文