I have created a new post that included an example application here.
Have a look at this markup:
In this page I have three dropdown lists with the CascadingDropDown extender attached to them, not going to go into details how I set them up (maybe some other time) though.
The issue was in this situation that when I clicked the “Save” button the error that you can see below appeared.
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation=”true”/> 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. at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
at System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument)
at System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection)
at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection)
at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Apparently it seems that when the items in the dropdowns where altered by client side code (as in the case with the CascadingDropDown extender) the asp.net runtime will recognize that the items in the dropdown are different from what was put in the viewstate which is not allowed.
You could of course set the EnableEventValidation=”false” as the page directive but we don´t really want to do that, do we?
The “badguy” apparently is the SupportsEventValidationAttribute that tells asp.net to perform this validation on the dropdowns which have this attribute
As MSDN says:
“If you do not define the SupportsEventValidationAttribute attribute, your custom control does not automatically participate in event validation”.
So the solution was to construct a custom class that inherits from DropDownList but does not include this attribute, like this:
So the new markup looks something like this:
…and now the click event fires like expected and the other validation logic on my page is still intact.