Recently at work, we ran into an issue where we needed to turn Page.EnableEventValidation on in our application. Yes, would you believe it, we had to turn it ON. Why did we have it off, you ask? Because when we migrated our app from 1.1 to 2.0, we didn't have the time to diagnose and fix the issues caused by leaving the event validation on.
Not only didn't we have the time to find out what was causing it, we didn't have the time to do the research as to what event validation is, and why it's there. Well, 2 years later, and I've made time to figure out what it is.
The purpose of event validation is to ensure that the posted value(s) of select lists are values that came from the application, and aren't something that has been injected into the page using malicious client script.
The example below shows how to test to see how event validation behaves. What I do is add a drop down list to the page, then through Java Script, I dynamically add a value to the drop down list.
When I choose the item from the drop down list that was added dynamically, I get the following error:
Under the covers, what happens is that ASP.NET makes a hash of all of the values that exist for the drop down list while the page is still on the server, and then stores that hash in a hidden input on the page.
When the page posts back, it verifies the values posted, with what exists in that hash. If it can't find it, and you have event validation turned on, then you'll get the exception.
Now, the above example is a very reasonable thing to do. However, if you want to do it, you've only go two options when it comes to event validation.
The first option is to turn off event validation for the page. Not the best plan, because now it's up to you to make sure that you're values are validated.
The second option is to tell the server all of the available values you're going to potentially be adding dynamically. To tell the server the possible values, you use the ClientScript.RegisterForEventValidation method. Again, not a perfect option, as some times you'll be able to identify these values, but sometimes you won't be able to anticipate all those values (AJAX'ified drop down list for instance).
Below is the same page above, but it uses the ClientScript.RegisterForEventValidation method in the overridden Render method (this method can only called during the render phase of the page lifecycle).