Friday, June 29, 2012

System.ArgumentException: Invalid postback or callback argument


This error occurs when the mapping between the controls in the .aspx page and the corresponding events in the code-behind file is changed.

For example if you try to fire the Button1_Click event while clicking Button2 then this error will occur.

Invalid postback or callback argument.  Event validation is enabled using &ltlpages enableEventValidation="true"/> in configuration or &ltl%@ 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.

This is done explicitly by Asp.net to make sure that there are no breach is security, to prevent some hacking script to trigger the code-behind events.

Solution
1. If your application is not a very critical or if it a restricted intranet application then you can set the
enableEventValidation attribute in the @Page directive to false, this will prevent Asp.net from checking the control-event mappings

EnableEventValidation="false"

2. If your application is critical then you can use the ClientScriptManager.RegisterForEventValidation method to register the postback.

Search Flipkart Products:
Flipkart.com

No comments: