本人在一个datalist控件添加了一个Imagebutton,数据库存储了图片地址和视频名字,为了实现动态绑定图片,并点击图片进入相关视频链接。
在Imagebutton的DataBinder里,ImageUrl属性为DataBinder.Eval(Container.DataItem,"ImageUrl"),CommandArgument属性绑定为DataBinder.Eval(Container.DataItem,"name"),其command属性设置为“play”。并添加了DataList_ItemCommand事件
这是我的代码:
protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt=new DataTable ();
        Connection con = new Connection("select *from  Video order by time Desc", dt);
        DataList1.DataSource = dt;
        DataList1.DataBind();    } public void AddressBack(DataListCommandEventArgs e)
    {
        //指定播放的页面
        Response.Redirect("~/flvplayer/flvplayer.aspx?name="+e .CommandArgument .ToString ());
       
    }
 protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "play")
        {
            AddressBack(e);
        }
    }执行后出现下面错误:
回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。可是当我在页面的<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 中添加 EnableEventValidation="false" 后点击图片没有任何反应。
如何修改?

解决方案 »

  1.   

    protected void Page_Load(object sender, EventArgs e)
      {
      DataTable dt=new DataTable ();
      Connection con = new Connection("select *from Video order by time Desc", dt);
      DataList1.DataSource = dt;
      DataList1.DataBind();  }=》protected void Page_Load(object sender, EventArgs e)
      {
    if(!IsPostBack)
    {
      DataTable dt=new DataTable ();
      Connection con = new Connection("select *from Video order by time Desc", dt);
      DataList1.DataSource = dt;
      DataList1.DataBind();
    }
      }
      

  2.   

    数据绑定 放在 if(!IsPostBack) 标明第一次加载时 数据是从数据库中获取的回发的时候  会通过ViewState 恢复数据的
      

  3.   

    if(!IsPostBack)
    没有它的话,第二次进来下边重新绑定数据源,把激发回来的事件给冲没了。