我在index.aspx中动态添加了用户控件,用户控件中绑定了一个datalist和一些按钮 ,结果我在运行界面的时候,发现点击用户控件中的按钮,但并没有触发click事件,而且断点也没进去,不知道是哪里出了问题 ,麻烦大家指教下。。

解决方案 »

  1.   


        protected void Page_Load(object sender, EventArgs e)
        {
          
                SmallClassID = Convert.ToInt32(hf.Value);
                PageIndex = 1;
                PageSize = 5;
                OrderBy = "createTime desc";
                BindDlSource();  
            
        } protected void BindDlSource()
        {
            RecordCount = NewsManager.GetNewsByPage(SmallClassID, PageIndex, PageSize, OrderBy).Count;
            lblCurrentPage.Text = "第" + PageIndex.ToString() + "页  共" + PageCount + "页";
            dlSource.DataSource = NewsManager.GetNewsByPage(SmallClassID, PageIndex, PageSize, OrderBy);
            dlSource.DataBind();
        }
        #region 分页
        //首页
        protected void btnFirst_Click(object sender, EventArgs e)
        {
            PageIndex = 1;
            BindDlSource();
        }    //上一页
        protected void btnPre_Click(object sender, EventArgs e)
        {
            if (PageIndex > 1)
                PageIndex--;
            BindDlSource();
        }    //下一页
        protected void btnNext_Click(object sender, EventArgs e)
        {
            if (PageIndex < PageCount)
                PageIndex++;
            BindDlSource();
        }    //末页
        protected void btnLast_Click(object sender, EventArgs e)
        {
            PageIndex = PageCount;
            BindDlSource();
        }    //跳转
        protected void btnGo_Click(object sender, EventArgs e)
        {
            try
            {
                int goPage = Convert.ToInt32(txtPage.Text.Trim());
                if (goPage >= 1 && goPage <= PageCount)
                {
                    PageIndex = goPage;
                    BindDlSource();
                }
            }
            catch
            {
                txtPage.Text = string.Empty;
            }
        }就是click的事件都没执行
      

  2.   

    page_onLoad加上这个if(!isPostback){
    }//再贴在页面上引用的代码!
      

  3.   

    加上if(!isPostback){ 

    的话 页面根本就不进去的
    把用户控件直接拖到界面上是可以用的 
    就动态加载的话 click的事件触发不了
    有没有谁知道呀~~~~~~~~~~~help啊~~~~~~~~
      

  4.   

      protected void rptTitle_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int smallClassId = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName == "getNews")
            {
                SmallClass smallClass = SmallClassManager.GetSmallClassById(smallClassId);
                switch (smallClass.TypeName)
                {
                    case "图片类":
                        ph.Dispose();
                        //ph.Controls.Clear();
                        Contorls_DLControl dl = Page.LoadControl("~/Contorls/dlControl.ascx") as Contorls_DLControl;
                        HiddenField pic = (HiddenField)dl.FindControl("hf");
                        pic.Value = smallClass.SmallClassId.ToString();
                        ph.Controls.Add(dl);
                        break;
                    case "信息类":
                        ph.Dispose();
                        //ph.Controls.Clear();
                        Contorls_GVControl gv = Page.LoadControl("~/Contorls/gvControl.ascx") as Contorls_GVControl;
                        HiddenField info = (HiddenField)gv.FindControl("hf");
                        info.Value = smallClass.SmallClassId.ToString();
                        ph.Controls.Add(gv);
                        break;
                    case "简介类":
                        ph.Dispose();
                        //ph.Controls.Clear();
                        Contorls_DVControl dv = Page.LoadControl("~/Contorls/dvControl.ascx") as Contorls_DVControl;
                        HiddenField intr = (HiddenField)dv.FindControl("hf");
                        intr.Value = smallClass.SmallClassId.ToString();
                        ph.Controls.Add(dv);
                        break;
                }
               
            }