关闭

asp.net中动态创建控件添加事件

603人阅读 评论(0) 收藏 举报

 for (int i = 0; i < colloa.Count; i++)
                {
                    LinkButton lb = new LinkButton();
                    lb.Text = colloa[i].AttachmentName;
                    lb.CommandArgument = colloa[i].AttachmentID.ToString();
                    lb.Click += new System.EventHandler(Button1_Click);
                    Literal lt = new Literal();
                    lt.Text = "<br>";
                    this.attachment.Controls.Add(lt);
                    this.attachment.Controls.Add(lb);
                }

 


   //下载
        public  void Button1_Click(object sender, EventArgs e)
        {

            int attchmentId = 25;// int.Parse();
            TradeCredit.CoreLibrary.BLL.O_Attachment oaBll = new TradeCredit.CoreLibrary.BLL.O_Attachment();
             TradeCredit.CoreLibrary.Entity.O_Attachment  oa = oaBll.GetModel(attchmentId);
            
             String savePath = Server.MapPath(oa.Path);   //@"C:/inetpub/wwwroot/tc/upload/";
             Down(savePath,oa.AttachmentName );
        }

 

   protected void Page_Load(object sender, EventArgs e)
        {
                    if (!IsPostBack)
                    {
                    }
            
                string sendFileID = Request.QueryString["sendFileID"];
                if (null != sendFileID && sendFileID.Length > 0)
                {
                    //查看回复
                    this.FileContent.Disabled = false;
                    InitWriteBackData(sendFileID);
                }
                            
        }

动态的添加 LinkButton lb = new LinkButton();控件。开始添加控件的方法放在!IsPostBack里面,结果不能调用方法,而且该控件自动消失。后来查了一下,原来动态加载控件、添加事件,这些东西要写在!isposeback外面。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:91301次
    • 积分:1473
    • 等级:
    • 排名:千里之外
    • 原创:35篇
    • 转载:45篇
    • 译文:0篇
    • 评论:2条
    最新评论