Friday, March 29, 2013

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.

One of my new comer collegue encountered this when he was trying to add a new row to a datatable bound to a GridView and trying to put the new row in edit mode. The error was pretty confusing and bewildering for a new comer :


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.


We, the somewhat experienced people are used to such errors and ignore them as a part of our life, but the new comers are not used to it! 

The notorious error is thrown when somebody rebinds data to a GridView in Page_Load, without PostBack check. A postback check like the following solved the error  in the Page_Load: 

            if (!Page.IsPostBack){
                          GridView1.DataSource = dt;
                          GridView1.DataBind();
                          }

No comments:

Post a Comment

Loop Engineering: Designing the Systems That Prompt Your Agents

Loop Engineering For the last couple of years, the core skill in working with AI was writing a good prompt. You'd craft careful instru...