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

 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外面。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值