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. 
这个错误怎么解决??

解决方案 »

  1.   

    ASP.net 添加了"event validation"的功能, ASP.NET会检查 POST方法中的所带的参数,如果认为不合法,就会抛出异常。这个设计的目的是为了防止恶意用户利用post 方法发送一些恶意数据,但是有时一些常见的case也会出错。1. 禁止这个功能, 但同时会失去一些安全保障:
    //—-通过web.config
    <system.web>
       <pages enableEventValidation="false"/>
    </system.web>
    //—-针对某个page
    <%@ Page EnableEventValidation="false" … %> 2.Register For Event Validation
    其原理就是让asp.net记录这个postback value.
    RegisterForEventValidation必须在render时调用.protected override void Render(HtmlTextWriter writer)
    {
       ClientScript.RegisterForEventValidation(_recipeList.UniqueID,"4");
       base.Render(writer);
    }如果我们自己写了一个control,需要使用validate events功能,就需要使用SupportsEventValidation attribute,[SupportsEventValidation]
    public class DynamicDropDownList : DropDownList
    {
      protected override void Render(System.Web.UI.HtmlTextWriter writer)
      {
         Page.ClientScript.RegisterForEventValidation(this.UniqueID, "4");
         base.Render(writer);
      }
    }目前,asp.net还不能单独禁止某个control的validate events功能.
    可以参考这个
    http://odetocode.com/Blogs/scott/archive/2006/03/20/3145.aspx
    http://odetocode.com/Blogs/scott/archive/2006/03/21/3153.aspx