ASP.NET - Error occur when Page is postback onclick event

Asked By ALOK RANJAN on 02-Jul-12 12:38 AM
hi everyone ,
                     I have problem when we call java script function on  onclick event of button like this.
                    <input id="btnsearch1" value="Search" type="submit" onclick='return btnSearch();'/>

                    <input id="btnsearch1" value="Search" type="submit" onclick="btnSearch();"/>

 we got following error,

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.

 plz provide me solution for this ASAP.


Alok ranjan

Neha Garg replied to ALOK RANJAN on 02-Jul-12 12:50 AM
Hello Alok,

For complete solution and the reason of that issue is given on the below link:
Neha Garg replied to ALOK RANJAN on 02-Jul-12 12:53 AM

Also you can follow the below things:

Just make sure your Web.Config file is up with Ajax scripts. Also, make sure - Scriptmanagers partial rendering is enabled

Disable eventvalidation (bad idea, because you lose a little of security that come with very little cost).

Use ASP.NET Ajax UpdatePanel. (Put the listbox in the Updatepanel and trigger a update, if you add or remove listbox. This way viewstate and related fields get updates and eventvalidation will pass.)

Forget client-side and use the classic postback and add or remove the listitems server-side.

Jitendra Faye replied to ALOK RANJAN on 02-Jul-12 01:02 AM
For this set


in page ditrective.

TSN ... replied to ALOK RANJAN on 02-Jul-12 01:33 AM

in you aspx file you should put the first line as this :

<%@ Page EnableEventValidation="false" %>