protected void GuestBookDL1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (ReplyB!=null)
        {
            ReplyB.Click += new EventHandler(btn_Click);
            
        } 
    }
    private void btn_Click(object sender, EventArgs e)
    {
        Response.Write("hello");
    }如果运行就出现错误:
异常详细信息: System.ArgumentException: 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
我看别人在datalist里面的button的click等事件都是这样用的?为什么会出错

解决方案 »

  1.   

    ReplyB是什么控件,可能EventArgs类型和委托参数类型不一致
      

  2.   

    回LS ReplyB是按钮
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;public partial class GuestBook : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            this.GuestBookDL1.DataSource = Article.GetDataTableOtherArticleByBoardId(1);
            this.DataBind();
        }
        protected void GuestBookDL1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            int ArtId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ArtId"));
            DataList GuestBookDL2 = (DataList)e.Item.FindControl("GuestBookDL2");
            if (GuestBookDL2!=null)
            {
                GuestBookDL2.DataSource = Article.GetDataTableRepley(ArtId);
                GuestBookDL2.DataBind();      
            }
            TextBox ReplyT = (TextBox)e.Item.FindControl("ReplyT");
            Button ReplyB = (Button)e.Item.FindControl("ReplyB");
            
            if (ReplyB!=null)
            {
                ReplyB.Click += new EventHandler(ReplyB_Click);
                
            }     
        }    void ReplyB_Click(object sender, EventArgs e)
        {
            Response.Write("Hello");
            throw new NotImplementedException();
        }
    }