Kartik
Kartik

Reputation: 651

ASP.NET Postback error

I am using C# to open a popup window and allow the user to select some value from that and send the value back to the server. However, when I close the pop-up window, I get the following error:


Invalid postback or callback argument. Event validation is enabled using <pagesenableEventValidation="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. "


Does anyone know what might cause this?

Upvotes: 0

Views: 2701

Answers (5)

seanb
seanb

Reputation: 6954

If your popup (or anything else) is injecting anything into the form which does the postback, then that may be the source of the error.

I have had this error when using hand wired jquery ajax calls to update cascading select lists (much faster than aspnet ajax), the new values that were put into the secondary select (which was runat=server) caused event validation to fail. You can either go through registering it all with the script manager (which I find a little painful), or disable event validation, but that does mean working a little harder and validating it all yourself.

Upvotes: 0

cgreeno
cgreeno

Reputation: 32371

This event validation mechanism reduces the risk of unauthorized postback requests and callbacks. With this model, a control registers its events during rendering and then validates the events during the post-back or callback handling. All event-driven controls in ASP.NET use this feature by default.

You can turn off EnableEventValidation in the PAGE or the web.config- but this is considered a security risk.

you might try:

unless necessary make sure bindings are done in - !Page.IsPostBack

Upvotes: 0

Jay S
Jay S

Reputation: 7994

I've seen this error when posting values back to the form that contain HTML markup or other restricted characters. By default, .NET blocks this for security reasons.

Check the values you are posting back to your page when closing the form to see if you are sending any markup in one of the input values.

If you absolutely have to send this type of data, disable the EnableEventValidation property on your ASPX page, and make sure to apply validation to prevent injection.

Upvotes: 1

Rex M
Rex M

Reputation: 144112

Turn off event validation. It's totally unnecessary as long as you check the form values yourself and make sure you don't accept invalid values.

Upvotes: 0

Andrew Arnott
Andrew Arnott

Reputation: 81791

The most common reason this error comes up (for me) is when you're creating controls yourself imperatively (in the code-behind) rather than declaratively in the .aspx file. And specifically when during the initial page rendering you create one set of controls, and during postback you're page creation logic creates a (possibly slightly) different set of controls. All the controls on the page must be created and added to the same position in the tree each time the page is rendered, whether on postback or not. Otherwise this error can result.

There may be other causes for this error as well, but this is the only scenario where I've seen it.

Upvotes: 0

Related Questions