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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 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();

}

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