惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Vercel News
Vercel News
C
Check Point Blog
G
Google Developers Blog
博客园 - 司徒正美
量子位
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
A
About on SuperTechFans
美团技术团队
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Cloudflare Blog
U
Unit 42

博客园 - GDLMO

给12306的建议 在delphi中引用第三方控件时,找不到dcu的解决办法 使用SqlBulkCopy时应注意Sqlserver表中使用缺省值的列 在sqlserver中使用bcp自动导出数据的方法和注意事项 无法识别的属性“requirePermission” sqlserver,将视图或表的记录不重复的插入到另一个表 让单元测试项目也能同步测试主程序的APP.CONFIG 水平太差,虽然认为Linq是个好东东,但有谁能教教我,怎么调试? Sqlserver 插入一条记录时,不重复插入的办法 dnn5.5.1的配置 关于EditUrl与NavigateURL的调用问题 DNN常用的几种页面跳转(EditUrl和Globals.NavigateURL) The Auto option has been disabled as the DotNetNuke Application cannot connect to a valid SQL Server database SQLite3中TimeStamp的使用问题 博文阅读密码验证 - 博客园 在DNN中使用SqlDataReader ExecuteReader(string connectionString, string spName, params object[] parameterValues)始终无法获得返回值 在DNN中使用jQuery的插件Validate Enter Null Values for DateTime Column of SQL Server(转) Web.Config和Sql Server2005连接字符串总结(转)
动态生成ASP.NET按钮时要注意的一个问题
GDLMO · 2010-11-22 · via 博客园 - GDLMO

   因为领导要求在模块的顶部将分类绑定(我个人认为没什么意义,但领导说的就一定有道理),于是有一个动态绑定按钮问题出来了,代码很简单:

代码

protected void BindBtn()
        {
            
if (CategoryIds.Length > 0)
            {
                
string[] split = CategoryIds.Split(',');
                
int[] cids = new int[split.Length];
                
for (int i = 0; i < split.Length; i++)
                {
                    cids[i] 
= int.Parse(split[i]);
                    LinkButton btn 
= new LinkButton();
                    btn.ID 
= "btnCategory" + cids[i].ToString();
                    btn.CommandArgument 
= cids[i].ToString();
                    CategoryController ctlCate 
= new CategoryController();
                    CategoryInfo infoCate 
= ctlCate.Get(cids[i], ArticleManagerModuleID);

                    btn.Text 

= infoCate != null ? infoCate.Name : "value = " + cids[i].ToString();

                    btn.Click 

+= new EventHandler(CategoryBtnClicked);

                    phCategory.Controls.Add(btn);
                    Label lbl 

= new Label();
                    lbl.Width 
= 10;
                    lbl.Height 
= 10;
                    phCategory.Controls.Add(lbl);
                }
            }
        }

却在调用时一直不能触发事件,怎么也没想明白,后来发现我将BindBtn放在了if(!IsPostBack) 中,代码如下:

if(!IsPostBack) 

    
//.......
    BindBtn();

}

由于动态生成的控件 ,有的生存周期。在初始化里面写的话,回发时就没了,响应不了。放到外面问题解决。