Invalid postback or callback argument in ASP.NET

While converting some php code to asp.net, I ran into the famous “Invalid postback or callback argument” on one of my webpages. This problem usually occurs when dealing with AJAX calls but my one was completely unrelated to that because I was not using any ajax at that point. The simplest solution that many people choose is to turn off Event Validation in their pages but you should never have to do that as the consequences can be far worse. You should therefore take the time to debug your application to understand where the problem is coming from.

For me the problem was caused by a nested form tag. ASP.NET allows only one form (with the runat attribute) per webpage whilst in PHP, you can have as many form tags as your heart wishes. While porting the code, I forgot to remove the nested form tag for a search functionality (actually I deliberately left the code for the form because I was testing something else) and that’s why asp.net was complaining about for its event validation. Once I’ve got that removed so that there was only one form per page, the error disappeared and the page worked as it should.

I might come back to this post to update with problems using AJAX and invalid callbacks when I implement ajax calls on the site I’m working on but for the time being, that should be it.

comments powered by Disqus