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
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:
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With