Invalid postback or callback argument. When clicking button

asp.netasp.net-ajaxcascadingdropdowninvalid-postback

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

Best Answer

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.

Related Topic