2010-08-03 85 views
5

我有一个网页与各种控制。其中两个是下拉列表。第一个下拉列表将从page_load事件的xml文件中填充。这工作正常。在第一个下拉列表中,附加了一个级联下拉列表扩展器,每当第一个下拉列表中的选择发生更改时,就会调用Web服务。这工作也很好。在我的两个dropdownlists下面,我有一个按钮,可以将页面返回。然而,当我在第二个下拉列表已经做出了选择,并点击按钮,我得到以下错误:回发或回调参数无效。当点击按钮

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

对不起,可怕的格式。有关为何引发此错误以及如何防止它的任何建议?

感谢,

回答

3

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

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

基本上你只是子类的DropDownList类摆脱了SupportsEventValidation属性 - > ASP.NET不验证值,一切运行良好!

这里阅读整篇帖子: Subclassing the DropDownList to remove the SupportsEventValidation attribute

+0

一个漂亮的解决方法,但仍然hacky国际海事组织。不要试图'破解'已经很烂的东西(即CDDL)。还是你的电话。 =) – RPM1984 2010-08-03 03:49:43

+0

我看了看更新面板,但卡住了。我想将第二个下拉列表的文本更改为“正在加载...”,而后台逻辑正在获取这些值。我正在使用附加到第一个下拉列表的onchange javascript。但是,文本更改正常,但回发似乎中断,没有值加载。任何想法如何解决这个问题? – b3n 2010-08-03 05:20:13

+0

我正在做同样的事情。我有一个下拉菜单:选择状态。当他们选择一个状态时,第二个下拉列表将文本设置为“加载城市...”,对Web服务进行ajax调用,并将其绑定到下拉列表。全部使用jQuery和Web服务调用。 (第一次ddl的onchange事件)。要在后台执行此操作,您需要异步调用Web服务,并提供回调函数 - 然后在回调函数中清除加载文本并绑定值。 – RPM1984 2010-08-03 05:57:55

3

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

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

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

我有同样的问题,这就是为什么我抛弃使用CascadingDropDown扩展,只是使用普通的客户端下拉列表的一些jQuery的。

你有两个选择:

  1. 沟AJAX CascadingDropDown,定期更换下拉菜单,在客户端点击使用jQuery/JavaScript的调用Web服务。
  2. 禁用页面上的事件验证。 (不建议)。

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

为了让CDDL能够正常工作,这不是你应该禁用的东西,因为它会影响整个页面并可能导致安全问题。

我的建议,咬紧牙关 - 沟CDDL和替换为jQuery。

+0

嗨RPM,谢谢你的回复。检查我上面的帖子中的链接,这很好,你不必关闭页面上的事件验证。 – b3n 2010-08-03 03:47:57

0

我已经搜查了很多,结束了以下解决方法: http://avinashsing.sunkur.com/2011/03/24/dropdownlist-in-asp-net-does-not-retain-control-state/

对于一般用户,在你的父页:

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

然后为您的页面中的每个DropDownList控件添加: OnDataBound =“cbGenericDropDownList_DataBound”

相关问题