views:

693

answers:

3

I have an ASP.net application that works fine in the development environment but in the production environment throws the following exception when clicking a link that performs a postback. Any ideas?

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.

Edit: This seems to only be happening when viewed with IE6 but not with IE7, any ideas?

A: 

It seems that the data/controls on the page are changed when the postback occurs. What happens if you turn off the event validation in the page directive.

<%@ Page ... EnableEventValidation = "false" />
azamsharp
I can't turn off the validation as I rely on it for other operations.
jwarzech
+1  A: 

This can happen if you're posting what appears to be possibly malicious things; such as a textbox that has html in it, but is not encoded prior to postback. If you are allowing html or script to be submitted, you need to encode it so that the characters, such as <, are passed as & lt;.

Nikki9696
A: 

I only ever get this when I have nested <form> tags in my pages. IE6 will look at the nested form tags and try to post the values in those forms as well as the main ASP.NET form, causing the error. Other browsers don't post the nested forms (since it's invalid HTML) and don't get the error.

You can certainly solve this by doing an EnableEventValidation = "false", but that can mean problems for your posted values and viewstate. It's better to weed out the nested <form> tags first.

There are other spots where this can come up, like HTML-esque values in form fields, but I think the error messages for those were more specific. On a generic postback that throws this, I'd just check the rendered page for extra <form> tags.

dnord