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

推荐订阅源

人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
Vercel News
Vercel News
D
Docker
博客园 - 聂微东
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
D
DataBreaches.Net
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | Blog
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
N
Netflix TechBlog - Medium
G
Google Developers Blog
腾讯CDC

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

}

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